:root {
  --ink: #1f2a24;
  --muted: #5f6b64;
  --line: #d9e0db;
  --paper: #ffffff;
  --wash: #f4f6f4;
  --green: #2f6b4f;
  --green-dark: #24543e;
  --green-wash: #e4f1ea;
  --red: #b3261e;
  --red-wash: #fbeceb;
  --amber: #7a5200;
  --amber-wash: #fbf1dc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--wash);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Source Han Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.7;
}

a { color: var(--green); }

h1 { margin: 0; font-size: 22px; line-height: 1.4; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.topbar form { margin: 0; }
.brand { color: var(--ink); font-size: 16px; font-weight: 600; text-decoration: none; }

.page { max-width: 1100px; margin: 0 auto; padding: 24px; }
.page-narrow { max-width: 480px; padding-top: 48px; }

.filing { padding: 8px 24px 24px; text-align: center; font-size: 12px; }
.filing a { color: var(--muted); text-decoration: none; }
.filing a:hover { text-decoration: underline; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }

.muted { margin: 0; color: var(--muted); }
.required { color: var(--red); }
.latin { font-style: italic; }
.latin-input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.nowrap { white-space: nowrap; }

.card {
  margin: 0 0 16px;
  padding: 20px 24px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
}
fieldset.card { min-width: 0; }
legend { padding: 0 8px; margin-left: -8px; font-size: 16px; font-weight: 600; }
.group-note { margin-bottom: 12px; }
.card h1 { margin-bottom: 12px; }
.empty { padding: 48px 24px; text-align: center; }
.empty p { margin: 0 0 16px; color: var(--muted); }

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; margin-bottom: 4px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #aeb9b2;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}
.field textarea { display: block; resize: vertical; }
.field .latin-input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.has-error input, .has-error textarea { border-color: var(--red); }
.hint { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.error { margin: 4px 0 0; color: var(--red); font-size: 14px; }
.error-summary, .flash {
  margin: 0 0 16px;
  padding: 10px 14px;
  border-radius: 6px;
}
.error-summary { background: var(--red-wash); color: var(--red); }
.flash { background: var(--green-wash); color: var(--green-dark); }

:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.button {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid #aeb9b2;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}
.button:hover { background: var(--wash); }
.button.primary { border-color: var(--green); background: var(--green); color: #fff; }
.button.primary:hover { background: var(--green-dark); }
.button.danger { border-color: var(--red); background: var(--red); color: #fff; }
.button.danger:hover { background: #8f1e18; }
.button.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.button.full { width: 100%; }
.link-button { padding: 0; border: 0; background: none; color: var(--green); font: inherit; text-decoration: underline; cursor: pointer; }
.danger-link { margin-left: 12px; color: var(--red); }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.filters .field { margin: 0; }
.filters .grow { flex: 1 1 280px; }
.filters input, .filters select, .filters .button { height: 42px; }
.filters .button { padding-top: 0; padding-bottom: 0; line-height: 40px; }

.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #fafbfa; color: var(--muted); font-size: 13px; font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 13px; white-space: nowrap; }
.badge.done { background: var(--green-wash); color: var(--green-dark); }
.badge.todo { background: var(--amber-wash); color: var(--amber); }

.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 16px; }
.form-actions { display: flex; gap: 12px; margin-top: 16px; }

.head-actions { display: flex; gap: 12px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.file-button { position: relative; }
.file-button:focus-within { outline: 2px solid var(--green); outline-offset: 2px; }
.photo-preview { display: block; max-width: 100%; max-height: 320px; margin-top: 16px; border-radius: 6px; }
[hidden] { display: none !important; }

.scan-layout { display: grid; grid-template-columns: minmax(200px, 300px) 1fr; gap: 16px; align-items: start; }
.scan-photo { margin: 0; padding: 12px; }
.scan-photo img { display: block; width: 100%; border-radius: 6px; }
.scan-photo figcaption { margin-top: 8px; color: var(--muted); font-size: 13px; text-align: center; }
.candidates { margin: 0; padding: 0; list-style: none; }
.candidate { display: flex; align-items: center; gap: 16px; padding: 16px; }
.candidate form { margin: 0; }
.candidate-thumb { flex: none; width: 80px; height: 80px; border-radius: 6px; background: var(--wash); object-fit: cover; }
.candidate-body { flex: 1; min-width: 0; }
.candidate-body h2 { margin: 0; font-size: 17px; line-height: 1.4; }
.candidate-body p { margin: 0; }
.candidate-actions { display: flex; flex: none; flex-direction: column; align-items: flex-end; gap: 8px; }
.score { color: var(--green-dark); font-weight: 600; }
.scan-again { margin-top: 4px; }

.notice { margin: 0 0 16px; padding: 12px 16px; border-radius: 6px; background: var(--amber-wash); color: var(--amber); }
.notice p { margin: 0; }
.notice p + p { margin-top: 6px; }
.notice-warning { font-weight: 600; }

@media (max-width: 720px) {
  .scan-layout { grid-template-columns: 1fr; }
  .candidate { flex-wrap: wrap; }
  .candidate-actions { width: 100%; align-items: stretch; }
  .candidate-actions .button { width: 100%; }
  .candidate-actions .badge { align-self: flex-start; }
}

.page-medium { max-width: 640px; }
.scan-error { margin-top: 12px; }
.scan-form { margin-top: 16px; }
.card > h1 + .muted { margin-top: -4px; }

.topbar { flex-wrap: wrap; gap: 8px 24px; }
.topnav { display: flex; flex: 1; gap: 16px; }
.topnav a { color: var(--ink); text-decoration: none; white-space: nowrap; }
.topnav a:hover { color: var(--green); text-decoration: underline; }
.tag-summary { margin-bottom: 12px; }

.tag-code { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: 0.04em; }
.card h2 { margin: 0 0 12px; font-size: 17px; line-height: 1.4; }
.bound-plant { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.bound-plant p { margin: 0; }
.bound-plant form { margin: 0; }
.search-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.search-row .field { flex: 1 1 240px; margin: 0; }
.search-row input, .search-row .button { height: 42px; }
.search-row .button { padding-top: 0; padding-bottom: 0; line-height: 40px; }
.plant-results { margin: 16px 0 0; padding: 0; list-style: none; }
.plant-results li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.plant-results form { margin: 0; }
.scheme-box { display: flex; gap: 8px; margin: 8px 0 16px; }
.scheme-box input { flex: 1; min-width: 0; padding: 8px 10px; border: 1px solid #aeb9b2; border-radius: 6px; background: var(--wash); color: var(--ink); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.write-steps { margin: 0 0 12px; padding-left: 1.5em; }
.write-steps li + li { margin-top: 6px; }
.inline-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.danger-link.delete-link { display: inline-block; margin: 4px 0 0; }
.quantity-field { flex: 0 0 96px !important; }
.card > .notice { margin-bottom: 12px; }
.flash.flash-warning { background: var(--amber-wash); color: var(--amber); }

.ai-item { margin-top: 16px; }
.ai-item h2 { margin: 0 0 4px; font-size: 15px; }
.ai-item p { margin: 0; white-space: pre-line; }
.ai-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.ai-actions form { margin: 0; }
