:root {
  --bg: #f6f4ef;
  --card: #fff;
  --ink: #23302c;
  --muted: #6b7772;
  --line: #e2ded5;
  --main: #2f6f5e;
  --main-soft: #e3efe9;
  --warn: #b5651d;
  --warn-soft: #fbefdc;
  --danger: #b33a3a;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 16px; line-height: 1.6;
}
body.noscroll { overflow: hidden; }
#app { max-width: 760px; margin: 0 auto; padding-bottom: calc(96px + var(--safe-b)); }
a { color: var(--main); }
.pad { padding: 12px 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.warn { color: var(--warn); background: var(--warn-soft); padding: 8px 10px; border-radius: 10px; }
.ellipsis { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ヘッダー */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: grid; grid-template-columns: 48px 1fr auto; align-items: center; gap: 4px;
  padding: calc(6px + env(safe-area-inset-top, 0px)) 8px 6px;
  background: rgba(246, 244, 239, .94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 18px; margin: 0; text-align: center; }
.bar h1:first-child { grid-column: 1 / 3; text-align: left; padding-left: 8px; }
.icon-btn, .text-btn {
  display: inline-flex; align-items: center; justify-content: center; min-width: 44px; height: 44px;
  font-size: 26px; text-decoration: none; color: var(--main); background: none; border: 0; cursor: pointer;
}
.text-btn { font-size: 16px; font-weight: 600; padding: 0 10px; }

/* 検索・絞り込み */
.search-wrap { padding: 10px 16px 4px; }
.search-wrap input {
  width: 100%; font-size: 16px; padding: 11px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: #fff;
}
.filters { display: flex; gap: 6px; padding: 6px 16px; overflow-x: auto; }
.filters select {
  flex: 0 0 auto; font-size: 14px; padding: 7px 8px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
}
.chips { display: flex; gap: 6px; padding: 4px 16px 8px; overflow-x: auto; }
.chip {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-size: 14px; cursor: pointer;
}
.chip.on { background: var(--main-soft); border-color: var(--main); color: var(--main); }
.chip.small { font-size: 13px; padding: 1px 8px; cursor: default; }
.chip button { border: 0; background: none; color: inherit; font-size: 16px; padding: 0 2px; cursor: pointer; }

.alert {
  margin: 4px 16px 8px; padding: 10px 12px; border-radius: 12px;
  background: var(--warn-soft); color: var(--warn); display: flex; flex-direction: column; gap: 2px;
}
.alert a { color: var(--warn); }
#count { padding: 0 16px; }

/* カード一覧 */
.cards { list-style: none; margin: 0; padding: 4px 16px; display: grid; gap: 10px; }
@media (min-width: 640px) { .cards { grid-template-columns: 1fr 1fr; } }
.card {
  display: flex; gap: 12px; padding: 10px; background: var(--card); border-radius: var(--radius);
  text-decoration: none; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.06); min-height: 96px;
}
.thumb {
  flex: 0 0 76px; width: 76px; height: 96px; object-fit: cover; border-radius: 8px; background: #eee;
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--muted);
}
.thumb.pdf { background: #fbe9e7; color: #c0392b; }
.card-body { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.card-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.snip { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.snip mark { background: #ffe58a; color: var(--ink); }
.empty-msg { text-align: center; color: var(--muted); padding: 40px 0; list-style: none; }
.badge { align-self: flex-start; font-size: 12px; padding: 1px 8px; border-radius: 999px; margin-top: 3px; }
.w-ok { background: var(--main-soft); color: var(--main); }
.w-soon { background: var(--warn-soft); color: var(--warn); font-weight: 700; }
.w-expired { background: #eee; color: var(--muted); }

.fab {
  position: fixed; right: 18px; bottom: calc(20px + var(--safe-b)); z-index: 20;
  background: var(--main); color: #fff; text-decoration: none; font-weight: 700;
  padding: 14px 20px; border-radius: 999px; box-shadow: 0 4px 14px rgba(47,111,94,.4);
}

/* 詳細 */
.pages { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin: 10px 0; }
.page { position: relative; padding: 0; border: 0; background: none; cursor: pointer; }
.page-img { width: 100%; aspect-ratio: 3/4; object-fit: cover; border-radius: 10px; background: #eee; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.page-img.pdf { background: #fbe9e7; color: #c0392b; }
.page-kind { position: absolute; left: 6px; bottom: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 6px; }
.info { background: var(--card); border-radius: var(--radius); padding: 4px 14px; margin: 10px 0; }
.info .row { display: grid; grid-template-columns: 6.5em 1fr; gap: 8px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.info .row:last-child { border-bottom: 0; }
.info dt { color: var(--muted); font-size: 14px; }
.info dd { margin: 0; word-break: break-word; }
.ocr { background: var(--card); border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; }
.ocr summary { cursor: pointer; font-weight: 600; }
.ocr pre { white-space: pre-wrap; font-family: inherit; font-size: 13px; max-height: 50vh; overflow: auto; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.primary { background: var(--main); border-color: var(--main); color: #fff; }
.btn.danger, button.danger { color: var(--danger); }
.btn.wide { width: 100%; margin-top: 8px; font-size: 17px; }

/* 編集フォーム */
.form section { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.form h2 { font-size: 15px; margin: 0 0 8px; color: var(--main); }
.form label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0; }
.form input:not([type=file]), .form select, .form textarea {
  display: block; width: 100%; margin-top: 3px; font-size: 16px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-family: inherit;
}
.form input[type=date] { min-height: 44px; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; }
.add-row .btn { flex: 1 1 140px; }
.edit-pages { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 8px; }
.edit-pages li { display: flex; gap: 10px; align-items: center; background: var(--bg); padding: 6px; border-radius: 10px; }
.edit-pages .thumb { flex-basis: 60px; width: 60px; height: 76px; }
.ep-body { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.ep-body select { margin: 0; padding: 6px 8px; }
.ep-btns { display: flex; gap: 6px; }
.ep-btns button { min-width: 40px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: #fff; font-size: 15px; cursor: pointer; }
.ep-btns button:disabled { opacity: .35; }
.tag-input { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick { display: flex; gap: 6px; }
.quick button { padding: 4px 12px; border-radius: 999px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 14px; }

.box { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.box h2 { font-size: 16px; margin: 0 0 6px; }

/* ビューア */
.viewer { position: fixed; inset: 0; z-index: 50; background: #111; display: flex; flex-direction: column; }
.viewer-bar {
  display: flex; justify-content: space-between; align-items: center; color: #fff;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 10px 8px; font-size: 14px;
}
.viewer-bar button { background: none; border: 0; color: #fff; font-size: 15px; padding: 8px; cursor: pointer; }
.viewer-body { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; -webkit-overflow-scrolling: touch; }
.viewer-body img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer.zoomed .viewer-body { display: block; }
.viewer.zoomed .viewer-body img { max-width: none; max-height: none; width: 220%; }
.viewer .nav {
  position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 64px;
  background: rgba(255,255,255,.15); color: #fff; border: 0; font-size: 30px; cursor: pointer; border-radius: 10px;
}
.viewer .prev { left: 6px; } .viewer .next { right: 6px; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: rgba(35,48,44,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.form.busy .edit-pages { opacity: .6; }
.members { margin: 4px 0 8px; padding-left: 1.2em; }
.code { font-size: 22px; letter-spacing: 3px; font-family: ui-monospace, Menlo, Consolas, monospace; }

/* 0.3：PDFサムネイル・自動補正・切り抜き・型番で探す（2026-12-05 Claude Code） */
.pdf-wrap { position: relative; display: block; padding: 0; overflow: hidden; }
.pdf-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pdf-tag { position: absolute; right: 4px; top: 4px; background: #c0392b; color: #fff; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; }
.fixed-tag { font-size: 12px; color: #1e7e4a; }
.find-pdf.disabled { color: var(--muted, #888); text-decoration: none; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.check input { width: auto; margin: 0; }
.cropper { position: fixed; inset: 0; z-index: 60; background: #111; display: flex; flex-direction: column; touch-action: none; }
.crop-stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 18px; min-height: 0; }
.crop-box { position: relative; line-height: 0; max-width: 100%; max-height: 100%; }
.crop-box img { max-width: calc(100vw - 36px); max-height: calc(100vh - 170px); user-select: none; -webkit-user-select: none; }
.crop-svg { position: absolute; left: 0; top: 0; overflow: visible; touch-action: none; }
.crop-svg polygon { fill: rgba(46, 134, 222, .18); stroke: #2e86de; stroke-width: 2; }
.crop-svg circle { fill: rgba(255, 255, 255, .9); stroke: #2e86de; stroke-width: 3; }
.crop-tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); color: #fff; font-size: 14px; }
.crop-tools button { background: #333; color: #fff; border: 1px solid #555; border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.crop-tools label { display: flex; align-items: center; gap: 6px; }
.crop-tools input { width: auto; margin: 0; }
