:root {
  --paper: #f6f3ec;
  --surface: #fffdf8;
  --ink: #17231d;
  --muted: #657169;
  --line: #d9ded7;
  --green: #1f5b43;
  --green-dark: #174633;
  --green-soft: #dce9df;
  --amber: #bd6f20;
  --red: #ae3b35;
  --white: #ffffff;
  --shadow: 0 14px 34px rgba(34, 48, 40, 0.08);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --header-height: 76px;
  --nav-height: 76px;
  --content-max: 760px;
  --tap-size: 48px;
  --page-pad: 18px;
  --font-ui: "Hiragino Sans", "Yu Gothic UI", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-width: 0; overflow-x: hidden; }

body {
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 90% 4%, rgba(31, 91, 67, 0.09), transparent 24rem),
    var(--paper);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

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

input, textarea, select {
  width: 100%;
  min-height: var(--tap-size);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  color: var(--ink);
  background: var(--white);
  font-size: 16px;
}

textarea { min-height: 92px; resize: vertical; }

button { color: inherit; }

button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgba(31, 91, 67, 0.24);
  outline-offset: 2px;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  height: calc(var(--header-height) + env(safe-area-inset-top));
  padding: calc(12px + env(safe-area-inset-top)) var(--page-pad) 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid rgba(217, 222, 215, 0.88);
  background: rgba(246, 243, 236, 0.94);
  backdrop-filter: blur(14px);
}

.brand-block h1, .dialog-heading h2 { margin: 0; font-size: 22px; letter-spacing: -0.04em; }
.eyebrow { margin: 0 0 2px; color: var(--green); font-size: 10px; font-weight: 800; letter-spacing: 0.16em; }
.header-actions { display: flex; align-items: center; gap: 8px; }

.sync-button, .icon-button, .nav-button, .chip, .media-pick, .secondary-button, .primary-button, .danger-button {
  min-height: var(--tap-size);
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.sync-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
}

.sync-button strong { font-size: 15px; }
.sync-button.is-syncing .sync-dot { animation: pulse 0.8s infinite alternate; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.sync-button.is-clear .sync-dot { background: var(--green); }

.icon-button {
  min-width: var(--tap-size);
  padding: 0 10px;
  border-radius: 50%;
  background: var(--green-soft);
  font-weight: 800;
}

.app-shell {
  width: min(100%, var(--content-max));
  min-height: calc(100vh - var(--header-height) - var(--nav-height));
  margin: 0 auto;
  padding: 22px var(--page-pad) calc(var(--nav-height) + 28px + env(safe-area-inset-bottom));
}

.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.page-heading h2 { margin: 0; font-size: 28px; line-height: 1.15; letter-spacing: -0.05em; }
.page-heading p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }

.record-form { display: grid; gap: 14px; }

.form-card, .record-card, .detail-card, .empty-card {
  border: 1px solid rgba(217, 222, 215, 0.92);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.form-card { padding: 17px; }
.step-heading { display: flex; align-items: center; gap: 11px; margin-bottom: 13px; }
.step-number { display: grid; place-items: center; flex: 0 0 30px; height: 30px; border-radius: 50%; color: var(--white); background: var(--green); font-size: 13px; font-weight: 800; }
.step-heading h3 { margin: 0; font-size: 17px; }
.optional { margin-left: auto; color: var(--muted); font-size: 12px; }
.field-label { display: block; margin: 12px 0 6px; font-size: 13px; font-weight: 700; }
.helper { color: var(--muted); font-size: 13px; line-height: 1.6; }

.chip-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.chip-grid.temperature { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.chip { position: relative; display: grid; place-items: center; padding: 10px 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--white); font-size: 14px; font-weight: 700; text-align: center; }
.chip input { position: absolute; width: 1px; height: 1px; min-height: 0; opacity: 0; }
.chip:has(input:checked) { border-color: var(--green); color: var(--green-dark); background: var(--green-soft); box-shadow: inset 0 0 0 1px var(--green); }
.temperature .chip[data-grade="A"]:has(input:checked) { color: var(--red); background: #f8e4e1; border-color: var(--red); box-shadow: inset 0 0 0 1px var(--red); }
.temperature .chip[data-grade="C"]:has(input:checked) { color: #3d5f79; background: #e5eef4; border-color: #6084a0; box-shadow: inset 0 0 0 1px #6084a0; }

.media-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.media-pick { display: grid; place-items: center; gap: 4px; min-width: 0; padding: 11px 6px; border: 1px dashed var(--green); border-radius: var(--radius-sm); color: var(--green-dark); background: var(--green-soft); font-size: 12px; font-weight: 800; text-align: center; }
.media-pick span:first-child { font-size: 22px; }
.media-pick.has-file { border-style: solid; background: var(--green); color: var(--white); }
.media-pick.is-recording { border-style: solid; border-color: var(--red); color: var(--white); background: var(--red); animation: pulse 0.8s infinite alternate; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.primary-button, .secondary-button, .danger-button { width: 100%; padding: 12px 18px; border-radius: var(--radius-md); font-size: 16px; font-weight: 800; }
.primary-button { color: var(--white); background: var(--green); box-shadow: 0 9px 22px rgba(31, 91, 67, 0.2); }
.primary-button:active { background: var(--green-dark); transform: translateY(1px); }
.secondary-button { border: 1px solid var(--green); color: var(--green); background: transparent; }
.danger-button { color: var(--red); background: #f8e4e1; }
.form-actions { display: grid; gap: 9px; margin-top: 4px; }

.bottom-nav {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: 0;
  width: min(100%, var(--content-max));
  height: calc(var(--nav-height) + env(safe-area-inset-bottom));
  padding: 8px var(--page-pad) calc(8px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 20px 20px 0 0;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 -10px 30px rgba(34, 48, 40, 0.08);
  transform: translateX(-50%);
  backdrop-filter: blur(14px);
}

.nav-button { display: flex; justify-content: center; align-items: center; gap: 7px; border-radius: var(--radius-md); color: var(--muted); background: transparent; font-size: 13px; font-weight: 800; }
.nav-button span:first-child { font-size: 22px; }
.nav-button.is-active { color: var(--white); background: var(--green); }

.record-list { display: grid; gap: 11px; }
.list-tools { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; margin-bottom: 14px; }
.list-tools .field-label { margin-top: 0; }
.export-link { display: inline-grid; place-items: center; width: auto; min-height: var(--tap-size); text-decoration: none; white-space: nowrap; }
.export-link[aria-disabled="true"] { opacity: 0.55; pointer-events: none; }
.record-card { width: 100%; padding: 16px; display: grid; grid-template-columns: 1fr auto; gap: 10px; border-color: var(--line); color: inherit; text-align: left; }
.record-card h3 { margin: 0 0 8px; font-size: 17px; }
.record-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.record-summary { margin: 10px 0 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.next-action-date { margin: 8px 0 0; color: var(--muted); font-size: 12px; font-weight: 700; }
.chevron { align-self: center; color: var(--green); font-size: 24px; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 2px 9px; border-radius: 999px; color: var(--green-dark); background: var(--green-soft); font-size: 12px; font-weight: 800; }
.badge.grade-a { color: var(--red); background: #f8e4e1; }
.badge.grade-c { color: #3d5f79; background: #e5eef4; }
.badge.pending { color: #76420d; background: #f8e5cd; }
.badge.overdue { color: var(--white); background: var(--red); }
.empty-card { padding: 42px 22px; text-align: center; }
.empty-card .empty-icon { font-size: 38px; }
.empty-card h3 { margin: 10px 0 6px; }
.empty-card p { margin: 0; color: var(--muted); font-size: 14px; }

.detail-card { padding: 18px; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 12px; }
.detail-item { min-width: 0; }
.detail-item.wide { grid-column: 1 / -1; }
.detail-label { margin: 0 0 4px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: 0.08em; }
.detail-value { margin: 0; overflow-wrap: anywhere; font-size: 15px; line-height: 1.55; white-space: pre-wrap; }
.asset-gallery { display: grid; gap: 10px; margin-top: 16px; }
.asset-card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--white); }
.asset-card img { display: block; width: 100%; max-height: 360px; object-fit: contain; background: #edf0eb; }
.asset-card audio { display: block; width: 100%; }
.asset-label { padding: 8px 11px; color: var(--muted); font-size: 12px; font-weight: 700; }

.ocr-card { margin-top: 14px; border-color: rgba(31, 91, 67, 0.28); }
.ocr-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.ocr-heading h3 { margin: 0; font-size: 19px; letter-spacing: -0.03em; }
.ocr-note { margin: 12px 0 16px; padding: 10px 12px; border-radius: var(--radius-sm); color: var(--muted); background: var(--green-soft); font-size: 12px; line-height: 1.55; }
.ocr-grid { padding-top: 2px; }
.ocr-unconfirmed { flex: 0 0 auto; color: #76420d; background: #f8e5cd; }
.ocr-confirmed { flex: 0 0 auto; color: var(--green-dark); background: var(--green-soft); }
.ocr-waiting { flex: 0 0 auto; color: var(--muted); background: #e9ece8; }
.confirm-ocr-button { margin-top: 18px; }
.audio-summary-card { border-color: rgba(189, 111, 32, 0.34); }

.follow-card { margin-top: 14px; }
.follow-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.follow-form .field-label { margin-top: 0; }
.follow-form > button { grid-column: 1 / -1; }
.follow-entry-form h4, .follow-entry-form .wide { grid-column: 1 / -1; }
.follow-entry-form h4, .follow-history h4 { margin: 0; font-size: 15px; }
.follow-history { display: grid; gap: 9px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.follow-item { padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--white); }
.follow-item > div { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.follow-item time { color: var(--muted); font-size: 12px; font-weight: 800; }
.follow-item p { margin: 9px 0 0; font-size: 14px; line-height: 1.55; white-space: pre-wrap; }

.key-dialog { width: min(calc(100% - 28px), 440px); padding: 20px; border: 0; border-radius: var(--radius-lg); color: var(--ink); background: var(--surface); box-shadow: 0 24px 70px rgba(20, 34, 27, 0.3); }
.key-dialog::backdrop { background: rgba(16, 29, 22, 0.46); backdrop-filter: blur(4px); }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; }
.key-dialog .primary-button { margin-top: 16px; }

.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(var(--nav-height) + 18px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 32px); padding: 11px 16px; border-radius: 999px; color: var(--white); background: var(--ink); box-shadow: var(--shadow); font-size: 13px; opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity 0.2s, transform 0.2s; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--red); }

@keyframes pulse { to { opacity: 0.25; } }

@media (min-width: 620px) {
  :root { --page-pad: 24px; }
  .record-form { grid-template-columns: 1fr 1fr; }
  .form-card.wide, .form-actions { grid-column: 1 / -1; }
}

@media (max-width: 430px) {
  .list-tools, .follow-form { grid-template-columns: 1fr; }
  .export-link { width: 100%; }
  .follow-form > button, .follow-entry-form h4, .follow-entry-form .wide { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

.scan-dialog { max-height: calc(100dvh - 28px); }
.scan-preview { display: block; width: 100%; max-height: 62dvh; margin-top: 16px; object-fit: contain; }
.scan-dialog > .primary-button, .badge-scan-button { margin-top: 14px; }
.scan-results-card { margin-top: 14px; }
.scan-result-list { margin: 16px 0 0; padding: 0; display: grid; gap: 10px; list-style: none; }
.scan-result-list li { padding-top: 10px; border-top: 1px solid var(--line); }
.scan-result-list time { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
