:root {
  --bg: #f5f7f4;
  --panel: #ffffff;
  --ink: #18201b;
  --muted: #66736a;
  --line: #dfe6dd;
  --accent: #176b52;
  --accent-2: #b44e2f;
  --soft: #eaf2ed;
  --warn: #fff3d6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

body.modal-open {
  overflow: hidden;
}

button,
.file-button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 38px;
  padding: 0 14px;
  border-radius: 7px;
  font: inherit;
  cursor: pointer;
}

button:hover,
.file-button:hover {
  border-color: var(--accent);
}

.shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
  width: 100%;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #eef4ef;
  padding: 20px 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
}

.mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 7px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
}

h2 {
  font-size: 24px;
}

.brand p,
.toolbar p,
.muted {
  color: var(--muted);
}

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

.nav-item {
  width: 100%;
  text-align: left;
}

.nav-item.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.main {
  padding: 22px;
  min-width: 0;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.compact-toolbar {
  margin-top: 22px;
  margin-bottom: 12px;
}

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

.predict-workspace {
  display: grid;
  grid-template-columns: minmax(360px, 1.05fr) minmax(300px, 0.55fr);
  gap: 18px;
  align-items: stretch;
  margin-bottom: 18px;
}

.drop-zone,
.results-panel,
.model-card,
.history-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.drop-zone {
  min-height: 500px;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

.drop-zone.dragging {
  border-color: var(--accent);
  background: var(--soft);
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
  font-size: 16px;
}

.empty-state strong {
  color: var(--ink);
  font-size: 24px;
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent);
  font-size: 34px;
  line-height: 1;
}

.drop-file-button {
  display: inline-grid;
  place-items: center;
  margin-top: 6px;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.preview {
  width: 100%;
  height: 100%;
  max-height: 70vh;
  object-fit: contain;
  display: block;
}

.hidden {
  display: none !important;
}

.results-panel {
  padding: 18px;
  min-height: 360px;
}

.result-summary {
  align-self: stretch;
}

.panel-title {
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

.top-result {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.top-label {
  font-size: 22px;
  font-weight: 750;
}

.confidence-pill {
  background: var(--soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 6px 10px;
  font-weight: 700;
}

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

.expanded-candidates-block {
  margin-top: 8px;
}

.expanded-empty {
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.candidate-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  cursor: zoom-in;
  transition:
    border-color 120ms ease,
    transform 120ms ease,
    box-shadow 120ms ease;
}

.candidate-card.primary {
  border-color: rgba(23, 107, 82, 0.45);
}

.candidate-card:hover,
.candidate-card:focus {
  border-color: rgba(23, 107, 82, 0.55);
  box-shadow: 0 10px 24px rgba(24, 32, 27, 0.08);
  outline: none;
  transform: translateY(-1px);
}

.candidate-images {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  height: 260px;
  background: #edf1ee;
}

.candidate-images img {
  width: 100%;
  height: 130px;
  object-fit: cover;
  display: block;
}

.candidate-images img:hover,
.candidate-images img:focus {
  outline: 2px solid rgba(23, 107, 82, 0.55);
  outline-offset: -2px;
}

.candidate-images.empty-samples {
  display: grid;
  place-items: center;
  height: 180px;
  color: var(--muted);
}

.candidate-body {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.candidate-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
}

.candidate-heading h3 {
  margin: 0 0 2px;
  font-size: 17px;
  line-height: 1.2;
}

.reranker-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 6px;
  border: 1px solid rgba(180, 78, 47, 0.35);
  border-radius: 7px;
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 750;
  vertical-align: 2px;
}

.reranker-rationale {
  font-size: 13px;
  line-height: 1.35;
}

.candidate-heading strong {
  font-size: 18px;
}

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

.bar-fill {
  height: 100%;
  background: var(--accent);
}

.warning {
  padding: 10px 12px;
  background: var(--warn);
  border: 1px solid #edd48a;
  border-radius: 7px;
  margin-bottom: 14px;
}

.llm-review {
  display: grid;
  gap: 6px;
  padding: 12px;
  background: #eef4ef;
  border: 1px solid #cbdad0;
  border-radius: 7px;
  margin-bottom: 14px;
}

.llm-review strong {
  color: var(--accent);
}

.llm-review p {
  color: var(--ink);
  line-height: 1.4;
}

.llm-review span {
  color: var(--muted);
  font-size: 13px;
}

.llm-review.error {
  background: #fff3d6;
  border-color: #edd48a;
}

.ai-check-block,
.species-block {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.ai-check-block .secondary-action,
.species-block .secondary-action {
  cursor: pointer;
  border: 0;
  font: inherit;
}

.ai-check-block .secondary-action:disabled,
.species-block .secondary-action:disabled {
  cursor: progress;
  opacity: 0.7;
}

.review-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.review-block {
  display: grid;
  gap: 8px;
  margin-top: 20px;
}

.review-block.collapsed .review-row {
  display: none;
}

.link-button {
  min-height: auto;
  width: max-content;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
}

.link-button:hover {
  text-decoration: underline;
  border-color: transparent;
}

.secondary-action {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 38px;
  margin-top: 18px;
  background: var(--soft);
  border-color: #cbdad0;
  color: var(--accent);
  font-weight: 650;
  text-align: center;
}

.class-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.class-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition:
    border-color 120ms ease,
    transform 120ms ease,
    box-shadow 120ms ease;
}

.class-card:hover,
.class-card:focus {
  border-color: rgba(23, 107, 82, 0.55);
  box-shadow: 0 10px 24px rgba(24, 32, 27, 0.08);
  outline: none;
  transform: translateY(-1px);
}

.sample-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  height: 92px;
  background: #e9eee9;
}

.sample-strip img {
  width: 100%;
  height: 92px;
  object-fit: cover;
}

.class-body {
  padding: 12px;
}

.class-body h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.class-detail {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: stretch;
  background: rgba(24, 32, 27, 0.58);
  padding: 22px;
}

.class-detail-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 18px;
  width: min(1480px, 100%);
  max-height: calc(100vh - 44px);
  margin: auto;
  overflow: hidden;
  background: var(--panel);
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.24);
}

.class-detail-close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 999px;
  font-size: 28px;
  line-height: 1;
  z-index: 1;
}

.class-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 22px;
  padding: 28px 72px 0 28px;
}

.class-detail-header h2 {
  font-size: 34px;
  line-height: 1.08;
}

.class-detail-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 12px;
  min-height: 0;
  overflow: auto;
  padding: 0 28px 28px;
}

.class-detail-images img {
  width: 100%;
  height: clamp(260px, 34vh, 460px);
  object-fit: contain;
  background: #edf1ee;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: zoom-in;
}

.class-detail-images img:hover,
.class-detail-images img:focus {
  border-color: rgba(23, 107, 82, 0.55);
  outline: none;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(0, 0, 0, 0.86);
}

.image-lightbox img {
  max-width: min(1600px, 100%);
  max-height: calc(100vh - 56px);
  object-fit: contain;
  background: #111;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

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

.history-item {
  display: grid;
  grid-template-columns: 84px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 10px;
}

.history-item img {
  width: 84px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
}

.model-card {
  padding: 18px;
  display: grid;
  gap: 12px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.metric {
  background: var(--soft);
  border-radius: 7px;
  padding: 12px;
}

.metric strong {
  display: block;
  font-size: 22px;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .predict-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 14px;
  }

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

@media (max-width: 560px) {
  .brand {
    margin-bottom: 12px;
  }

  .mark {
    width: 34px;
    height: 34px;
    font-size: 14px;
  }

  h1 {
    font-size: 16px;
  }

  h2 {
    font-size: 22px;
  }

  nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  button,
  .file-button {
    min-height: 36px;
    padding: 0 10px;
    font-size: 14px;
  }

  .nav-item {
    text-align: center;
    padding: 0 6px;
  }

  .main {
    padding: 14px;
  }

  .toolbar {
    align-items: flex-start;
    margin-bottom: 12px;
  }

  #new-image-button {
    flex: 0 0 auto;
  }

  .predict-workspace {
    gap: 12px;
    margin-bottom: 12px;
  }

  .drop-zone {
    min-height: 0;
    aspect-ratio: 4 / 5;
    width: 100%;
  }

  .preview {
    max-height: none;
  }

  .results-panel {
    min-height: 0;
    padding: 14px;
  }

  .top-label {
    font-size: 19px;
    line-height: 1.2;
  }

  .candidate-images {
    height: 220px;
  }

  .candidate-images img {
    height: 110px;
  }

  .history-item {
    grid-template-columns: 64px 1fr;
  }

  .history-item .confidence-pill {
    grid-column: 2;
    width: max-content;
  }

  .class-detail {
    padding: 10px;
  }

  .class-detail-panel {
    max-height: calc(100vh - 20px);
  }

  .class-detail-header {
    display: grid;
    padding: 18px 56px 0 18px;
  }

  .class-detail-header h2 {
    font-size: 24px;
  }

  .class-detail-images {
    grid-template-columns: minmax(0, 1fr);
    padding: 0 18px 18px;
  }

  .class-detail-images img {
    height: clamp(220px, 42vh, 420px);
  }
}
