:root {
  color-scheme: light;
  --bg: #f4f8f5;
  --surface: #ffffff;
  --surface-strong: #eef7f2;
  --ink: #22302c;
  --muted: #6c7d78;
  --line: #d8e7df;
  --brand: #16826f;
  --brand-dark: #0f6659;
  --brand-soft: #dff3ed;
  --danger: #b84444;
  --shadow: 0 16px 40px rgba(28, 61, 50, 0.11);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(22, 130, 111, 0.12), transparent 30rem),
    linear-gradient(180deg, #f8fbf9 0%, var(--bg) 100%);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  max-width: 1220px;
  margin: 0 auto;
  padding: 2rem 1.25rem 1.25rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.eyebrow {
  margin: 0 0 0.3rem;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  line-height: 1.15;
}

.app-shell {
  max-width: 1220px;
  margin: 0 auto;
  padding: 0 1.25rem 2rem;
}

.toolbar {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.search-box,
.filter-box {
  flex: 1;
  display: grid;
  gap: 0.45rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.search-box {
  min-width: min(28rem, 100%);
}

.filter-box {
  flex: 0 1 13rem;
}

.search-box input,
.filter-box select,
.form-grid input,
.form-grid select,
.form-grid textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-box input {
  min-height: 3rem;
  padding: 0 1rem;
}

.filter-box select {
  min-height: 3rem;
  padding: 0 0.8rem;
}

.form-grid input,
.form-grid select {
  min-height: 2.7rem;
  padding: 0 0.8rem;
}

.form-grid textarea {
  resize: vertical;
  padding: 0.75rem 0.8rem;
}

.search-box input:focus,
.filter-box select:focus,
.form-grid input:focus,
.form-grid select:focus,
.form-grid textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(22, 130, 111, 0.12);
}

.stats {
  min-width: 8rem;
  display: grid;
  place-items: center;
  padding: 0.65rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.view-toggle {
  display: flex;
  align-self: end;
  min-height: 3rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.toggle-btn {
  min-width: 4rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.toggle-btn.active {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.stats strong {
  display: block;
  color: var(--brand-dark);
  font-size: 1.55rem;
  line-height: 1;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(22rem, 0.9fr);
  gap: 1rem;
  align-items: start;
}

.content-grid.grid-mode {
  grid-template-columns: 1fr;
}

.list-panel,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.list-panel {
  min-height: 34rem;
  overflow: hidden;
}

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

.panel-head h2 {
  margin-bottom: 0;
  font-size: 1.1rem;
}

.panel-head span {
  color: var(--muted);
  font-size: 0.88rem;
}

.record-list {
  display: grid;
}

.specimen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 1rem;
  padding: 1rem;
}

.record-card {
  display: grid;
  grid-template-columns: 5.8rem minmax(0, 1fr);
  gap: 0.9rem;
  width: 100%;
  padding: 0.85rem 1rem;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: inherit;
  text-align: left;
}

.record-card:hover,
.record-card.active {
  background: var(--surface-strong);
}

.grid-card {
  display: grid;
  grid-template-rows: auto 1fr;
  width: 100%;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
  text-align: left;
  box-shadow: 0 10px 24px rgba(28, 61, 50, 0.08);
}

.grid-card:hover {
  border-color: rgba(22, 130, 111, 0.38);
  transform: translateY(-1px);
}

.grid-photo {
  width: 100%;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(135deg, #d9efe8, #f6fbf8);
  color: var(--brand-dark);
  font-weight: 700;
}

.grid-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.grid-no-photo {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.grid-info {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
  padding: 0.75rem;
}

.grid-info strong,
.grid-info em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.grid-info em {
  color: var(--muted);
  font-size: 0.85rem;
}

.grid-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.thumb {
  width: 5.8rem;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background: linear-gradient(135deg, #d9efe8, #eff8f5);
  color: var(--brand-dark);
  font-weight: 700;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.record-main {
  min-width: 0;
}

.record-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.record-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1.02rem;
}

.badge {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 0.78rem;
}

.latin {
  margin-bottom: 0.35rem;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.9rem;
  font-style: italic;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.75rem;
  color: var(--muted);
  font-size: 0.84rem;
}

.detail-panel {
  position: sticky;
  top: 1rem;
  min-height: 34rem;
  padding: 1.1rem;
}

.detail-placeholder {
  height: 30rem;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--muted);
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.detail-title h2 {
  margin-bottom: 0.25rem;
  font-size: 1.35rem;
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
}

.info-list {
  display: grid;
  gap: 0.65rem;
  margin: 1rem 0;
}

.info-row {
  display: grid;
  grid-template-columns: 5rem minmax(0, 1fr);
  gap: 0.75rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
}

.info-row span:first-child {
  color: var(--muted);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
  gap: 0.75rem;
}

.photo-grid a,
.photo-preview-item {
  display: block;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.photo-grid img,
.photo-preview-item img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}

.primary-btn,
.secondary-btn,
.danger-btn,
.small-btn,
.icon-btn {
  border: 0;
  border-radius: 8px;
  transition: transform 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.primary-btn {
  min-height: 2.75rem;
  padding: 0 1rem;
  background: var(--brand);
  color: white;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(22, 130, 111, 0.2);
}

.primary-btn:hover {
  background: var(--brand-dark);
}

.secondary-btn,
.small-btn {
  min-height: 2.35rem;
  padding: 0 0.8rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.secondary-btn.is-admin {
  border-color: rgba(22, 130, 111, 0.35);
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 700;
}

.danger-btn {
  min-height: 2.35rem;
  padding: 0 0.8rem;
  background: #fdeeee;
  color: var(--danger);
}

.icon-btn {
  width: 2.2rem;
  height: 2.2rem;
  background: var(--surface-strong);
  color: var(--ink);
  font-size: 1.35rem;
  line-height: 1;
}

.dialog {
  width: min(46rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(18, 38, 34, 0.42);
}

.dialog form {
  padding: 1.1rem;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.dialog-head h2 {
  margin-bottom: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.85rem;
}

.form-grid label {
  display: grid;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.file-box input {
  padding: 0.65rem;
}

.photo-section {
  margin-top: 1rem;
}

.photo-section h3 {
  margin-bottom: 0.65rem;
  font-size: 1rem;
}

.photo-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.5rem, 1fr));
  gap: 0.75rem;
  min-height: 2rem;
}

.photo-preview-item {
  position: relative;
}

.remove-photo {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  width: 1.9rem;
  height: 1.9rem;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--danger);
  font-weight: 800;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.1rem;
}

.empty-state {
  padding: 4rem 1rem;
  color: var(--muted);
  text-align: center;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(24rem, calc(100vw - 2rem));
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: var(--ink);
  color: white;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(0.75rem);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

@media (max-width: 860px) {
  .app-header,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .app-header {
    display: grid;
  }

  .toolbar > * {
    flex-basis: 100%;
  }

  .detail-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .form-grid,
  .record-card {
    grid-template-columns: 1fr;
  }

  .thumb {
    width: 100%;
  }

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