:root {
  --paper: #f7f5ef;
  --surface: #ffffff;
  --ink: #20241f;
  --muted: #6d726b;
  --line: #dcded7;
  --accent: #193f34;
  --accent-soft: #e4ece8;
  --master: #18794e;
  --master-soft: #e2f4e9;
  --ok: #1769aa;
  --ok-soft: #e4f1fb;
  --mid: #8a6200;
  --mid-soft: #fff1b8;
  --bad: #b4312b;
  --bad-soft: #fbe8e6;
  --hold: #6f42a5;
  --hold-soft: #f0e9f8;
  --shadow: 0 12px 30px rgba(30, 36, 31, 0.14);
  font-family: "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(23, 105, 170, .28); outline-offset: 2px; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: max(12px, env(safe-area-inset-top)) 14px 12px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 2px 12px rgba(25, 63, 52, .22);
}

.brand-row, .subject-row, .sort-row, .quick-date-row, .range-row, .two-buttons { display: flex; align-items: center; gap: 8px; }
.brand-row > div:first-child { flex: 1; min-width: 0; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 1.35rem; letter-spacing: .02em; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
h2 { margin-bottom: 0; font-size: 1.25rem; }
h3 { margin-bottom: 8px; font-size: 1rem; }
.eyebrow { margin-bottom: 2px; font-size: .7rem; font-weight: 700; letter-spacing: .12em; opacity: .75; }
.subject-row { margin-top: 10px; }
.grow { flex: 1; min-width: 0; }

.icon-button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 0;
  border-radius: 50%;
  color: inherit;
  background: rgba(255,255,255,.12);
  font-size: 1.35rem;
  line-height: 1;
}
.icon-button:disabled { opacity: .35; cursor: default; }
.select-wrap select, input[type="date"], input[type="text"], input[type="number"], textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  background: var(--surface);
}
.app-header .select-wrap select { border-color: transparent; color: var(--ink); font-weight: 700; }

.primary-button, .secondary-button, .file-button {
  min-height: 44px;
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 700;
}
.primary-button { border: 1px solid var(--accent); color: #fff; background: var(--accent); }
.secondary-button, .file-button { border: 1px solid var(--line); background: var(--surface); }
.app-header .secondary-button { border-color: rgba(255,255,255,.38); color: #fff; background: transparent; }
.compact { padding-inline: 10px; white-space: nowrap; }
.full { width: 100%; }

main { width: min(100%, 900px); margin: 0 auto; padding: 12px 10px calc(28px + env(safe-area-inset-bottom)); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-bottom: 10px; }
.stat-card { min-width: 0; padding: 10px 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.stat-card strong { display: block; font-size: 1.25rem; line-height: 1.15; }
.stat-card span { display: block; margin-top: 3px; color: var(--muted); font-size: .69rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-card.rating-ok { border-top: 3px solid var(--ok); }
.stat-card.rating-master { border-top: 3px solid var(--master); }
.stat-card.rating-mid { border-top: 3px solid #e0b300; }
.stat-card.rating-bad { border-top: 3px solid var(--bad); }
.stat-card.hold-stat { border-top: 3px solid var(--hold); }

.controls { padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: rgba(255,255,255,.72); }
.quick-date-row { justify-content: space-between; margin-bottom: 9px; }
.quick-date-row label, .date-filter-wrap label { color: var(--muted); font-size: .78rem; font-weight: 700; }
.quick-date-row input { width: 158px; }
.filter-scroll { display: flex; gap: 6px; overflow-x: auto; padding: 2px 1px 7px; scrollbar-width: none; }
.filter-scroll::-webkit-scrollbar { display: none; }
.filter-chip {
  min-width: 52px;
  min-height: 38px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 12px;
  background: var(--surface);
  font-weight: 700;
}
.filter-chip.active { border-color: var(--accent); color: #fff; background: var(--accent); }
.filter-chip.rating-master:not(.active) { color: var(--master); background: var(--master-soft); }
.filter-chip.rating-ok:not(.active) { color: var(--ok); background: var(--ok-soft); }
.filter-chip.rating-mid:not(.active) { color: var(--mid); background: var(--mid-soft); }
.filter-chip.rating-bad:not(.active) { color: var(--bad); background: var(--bad-soft); }
.date-filter-wrap { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; margin: 2px 0 9px; }
.sort-row { border-top: 1px solid var(--line); padding-top: 9px; }
.view-toggle { display: flex; overflow: hidden; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.view-toggle button { width: 42px; min-height: 42px; border: 0; background: transparent; font-size: 1.1rem; }
.view-toggle button.active { color: #fff; background: var(--accent); }
.result-count { margin: 7px 2px -2px; color: var(--muted); font-size: .75rem; }
.quick-tools { display: flex; gap: 6px; overflow-x: auto; margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line); scrollbar-width: none; }
.quick-tools::-webkit-scrollbar { display: none; }
.quick-tools button { min-height: 36px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 9px; padding: 5px 9px; background: var(--surface); color: var(--muted); font-size: .72rem; font-weight: 700; }
.advanced-active { box-shadow: inset 0 0 0 2px var(--accent); }

.proof-list { margin-top: 9px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--surface); }
.proof-row { display: grid; grid-template-columns: 48px minmax(62px, 1fr) 38px 30px repeat(4, 42px); align-items: center; min-height: 58px; border-bottom: 1px solid var(--line); }
.proof-row:last-child { border-bottom: 0; }
.proof-number {
  align-self: stretch;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fafaf7;
  color: var(--accent);
  font-size: 1rem;
  font-weight: 800;
}
.proof-meta { min-width: 0; padding: 6px 8px; }
.proof-meta time { display: block; font-size: .77rem; font-weight: 700; }
.proof-meta span { display: block; color: var(--muted); font-size: .67rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hold-label { display: inline-flex !important; align-items: center; width: max-content; max-width: 100%; margin-top: 2px; border-radius: 999px; padding: 2px 6px; color: var(--hold) !important; background: var(--hold-soft); font-size: .62rem !important; font-weight: 800; }
.proof-row.on-hold, .proof-card.on-hold { background: #faf8fc; }
.proof-row.on-hold > :not(.proof-number), .proof-card.on-hold > :not(.card-top) { opacity: .78; }
.proof-row.on-hold .proof-number, .proof-card.on-hold .proof-number { box-shadow: inset 4px 0 0 var(--hold); }
.latest-badge { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; font-weight: 900; }
.latest-badge.empty { color: #9a9e98; background: #f0f1ee; }
.count-badge { color: var(--muted); text-align: center; font-size: .72rem; font-variant-numeric: tabular-nums; }
.quick-rating {
  width: 38px;
  height: 40px;
  border: 0;
  border-radius: 9px;
  font-weight: 900;
  font-size: 1rem;
}
.quick-rating:disabled { opacity: .38; cursor: default; }
.rating-master { color: var(--master); background: var(--master-soft); }
.rating-ok { color: var(--ok); background: var(--ok-soft); }
.rating-mid { color: var(--mid); background: var(--mid-soft); }
.rating-bad { color: var(--bad); background: var(--bad-soft); }

.proof-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 9px; background: transparent; border: 0; overflow: visible; }
.proof-grid .proof-card { overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.card-top { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 5px 7px 5px 0; }
.proof-grid .proof-number { width: 45px; min-height: 40px; border-right: 1px solid var(--line); border-bottom: 0; }
.card-info { padding: 0 7px 7px; color: var(--muted); font-size: .65rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-buttons { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); }
.card-buttons .quick-rating { width: 100%; height: 40px; border-radius: 0; border-right: 1px solid rgba(0,0,0,.06); }

.empty-state { padding: 64px 20px; text-align: center; color: var(--muted); }
.hidden { display: none !important; }

.sync-button { position: relative; }
.sync-dot { position: absolute; right: 5px; bottom: 5px; width: 8px; height: 8px; border: 2px solid var(--surface, #fff); border-radius: 50%; background: #777; }
.sync-button[data-state="synced"] .sync-dot { background: #16845b; }
.sync-button[data-state="syncing"] .sync-dot { background: #e0a700; animation: sync-pulse 1s infinite alternate; }
.sync-button[data-state="pending"] .sync-dot, .sync-button[data-state="offline"] .sync-dot { background: #d48400; }
.sync-button[data-state="error"] .sync-dot { background: #c83434; }
@keyframes sync-pulse { to { transform: scale(1.45); opacity: .55; } }
.sync-status-card { display: grid; gap: 5px; padding: 14px; border: 1px solid var(--line, #ddd); border-radius: 14px; background: #fafafa; }
.sync-status-card span { color: var(--muted, #666); font-size: .86rem; }
.hold-filter { border-color: #7a4aa0 !important; color: #64348b; }
.hold-filter.active { color: #fff !important; background: #70408f !important; }
.filter-notice { margin: 6px 0 0; padding: 7px 10px; border-radius: 10px; color: #5d347d; background: #f2e9f7; font-size: .82rem; }
.filter-notice button { border: 0; padding: 3px 7px; color: inherit; background: transparent; text-decoration: underline; }
.compact-actions { gap: 7px; }
.danger-button { min-height: 44px; border: 1px solid #b74747; border-radius: 10px; color: #a12626; background: #fff; font: inherit; font-weight: 700; }
.divider { display: flex; align-items: center; gap: 8px; color: var(--muted, #666); font-size: .8rem; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--line, #ddd); }
.all-hold-row { display: grid; gap: 6px; padding: 11px; border: 1px solid #d9c7e4; border-radius: 12px; background: #fbf8fd; }
.all-hold-row header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.all-hold-row small { color: var(--muted, #666); }
.conflict-list { display: grid; gap: 10px; max-height: 48vh; overflow: auto; }
.conflict-item { padding: 10px; border: 1px solid var(--line, #ddd); border-radius: 10px; background: #fafafa; }
.conflict-item strong { display: block; margin-bottom: 6px; }
.conflict-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.conflict-compare pre { min-width: 0; max-height: 150px; margin: 0; padding: 7px; overflow: auto; border-radius: 7px; background: #fff; font-size: .68rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

dialog { padding: 0; border: 0; color: var(--ink); background: transparent; }
dialog::backdrop { background: rgba(20, 26, 22, .48); backdrop-filter: blur(2px); }
.sheet-dialog { width: min(100%, 620px); max-height: 88vh; margin: auto 0 0; border-radius: 18px 18px 0 0; }
.modal-dialog { width: min(calc(100% - 28px), 480px); max-height: calc(100vh - 28px); margin: auto; border-radius: 16px; }
.dialog-shell { max-height: inherit; overflow: auto; background: var(--surface); }
.dialog-header { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.dialog-header .icon-button { color: var(--ink); background: #f0f1ee; }
.dialog-body { padding: 14px 14px max(18px, env(safe-area-inset-bottom)); }
.form-stack { display: grid; gap: 14px; }
.form-stack label { display: grid; gap: 6px; color: var(--muted); font-size: .8rem; font-weight: 700; }
.range-row > label { flex: 1; }
.range-row > span { padding-top: 23px; }
fieldset { margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 6px; color: var(--muted); font-size: .8rem; font-weight: 700; }
.rating-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.rating-picker label { position: relative; display: block; }
.rating-picker input { position: absolute; opacity: 0; pointer-events: none; }
.rating-picker span { display: grid; place-items: center; min-height: 66px; border: 2px solid transparent; border-radius: 11px; font-size: 1.4rem; font-weight: 900; }
.rating-picker small { font-size: .63rem; font-weight: 700; }
.rating-picker input:checked + span { border-color: currentColor; box-shadow: 0 0 0 2px #fff inset; }
.compact-picker span { min-height: 52px; }
.form-error { min-height: 1.2em; margin: -5px 0 0; color: var(--bad); font-size: .78rem; }

.subject-list, .history-list { display: grid; gap: 8px; margin-bottom: 12px; }
.subject-item, .history-item { display: flex; align-items: center; gap: 9px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.subject-item-main, .history-main { flex: 1; min-width: 0; }
.subject-item-main strong, .history-main strong { display: block; }
.subject-item-main span, .history-main span { display: block; color: var(--muted); font-size: .74rem; overflow-wrap: anywhere; }
.small-button { min-width: 42px; min-height: 40px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); font-weight: 700; }
.small-button.danger { color: var(--bad); }
.history-rating { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 10px; font-size: 1.2rem; font-weight: 900; }
.hold-status-panel { display: grid; gap: 8px; margin-bottom: 12px; padding: 12px; border: 1px solid #d9c9ea; border-radius: 12px; background: var(--hold-soft); }
.hold-status-panel p { margin: 0; color: #56347d; font-size: .78rem; line-height: 1.55; }
.hold-status-panel strong { color: var(--hold); }
.hold-actions { display: flex; gap: 7px; }
.hold-actions button { flex: 1; }
.hold-history { display: grid; gap: 5px; margin-top: 2px; padding-top: 8px; border-top: 1px solid #d9c9ea; }
.hold-history span { color: var(--muted); font-size: .68rem; }

.data-actions { display: grid; gap: 10px; }
.data-card { padding: 13px; border: 1px solid var(--line); border-radius: 12px; }
.data-card p { margin-bottom: 12px; color: var(--muted); font-size: .8rem; line-height: 1.65; }
.data-card.subtle { background: #f7f8f5; }
.two-buttons > * { flex: 1; }
.file-button { display: grid; place-items: center; width: 100%; cursor: pointer; }
.file-button input { position: absolute; opacity: 0; pointer-events: none; }
.import-preview { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.import-preview p { margin-bottom: 8px; }

.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); width: max-content; max-width: calc(100% - 28px); transform: translate(-50%, 20px); padding: 11px 15px; border-radius: 10px; color: #fff; background: #242925; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: .2s ease; font-size: .82rem; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

@media (min-width: 600px) {
  .app-header { padding-inline: max(18px, calc((100vw - 900px) / 2)); }
  main { padding-inline: 18px; }
  .stats { grid-template-columns: repeat(7, 1fr); }
  .proof-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .sheet-dialog { margin: auto; border-radius: 18px; }
}

@media (max-width: 390px) {
  .proof-row { grid-template-columns: 42px minmax(48px, 1fr) 34px 27px repeat(4, 36px); }
  .quick-rating { width: 34px; height: 38px; }
  .proof-meta { padding-inline: 6px; }
  .sort-row { flex-wrap: wrap; }
  .sort-row .select-wrap { flex-basis: calc(100% - 92px); }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}
.action-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; margin-bottom: 10px; }
.action-strip button { min-height: 54px; border: 1px solid var(--line); border-radius: 12px; padding: 5px 2px; color: var(--accent); background: var(--surface); font-size: .68rem; font-weight: 800; }
.action-strip span { display: block; margin-bottom: 1px; font-size: .95rem; }

.compact-label { display: grid; gap: 5px; margin-bottom: 10px; color: var(--muted); font-size: .75rem; font-weight: 700; }
.compact-label select, .form-stack select { min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--surface); }
.confirm-message { margin: 0; padding: 14px; border-radius: 11px; background: var(--accent-soft); font-weight: 800; line-height: 1.6; }
.duplicate-options { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 11px; }
.duplicate-options p { margin: 0 0 2px; color: var(--bad); font-size: .8rem; font-weight: 700; }
.duplicate-options label, .check-stack label, .switch-label { display: flex; align-items: center; gap: 9px; min-height: 38px; color: var(--ink); font-size: .8rem; font-weight: 600; }
.duplicate-options input, .check-stack input, .switch-label input, .check-grid input { width: 20px; height: 20px; accent-color: var(--accent); }
.check-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.check-grid label { display: grid; place-items: center; gap: 4px; min-height: 54px; border: 1px solid var(--line); border-radius: 9px; background: #fafaf7; font-weight: 800; }
.check-stack { display: grid; gap: 4px; }

.selection-bar { position: fixed; z-index: 30; left: 50%; bottom: 0; width: min(100%, 620px); transform: translateX(-50%); padding: 10px 12px max(10px, env(safe-area-inset-bottom)); border-radius: 16px 16px 0 0; color: #fff; background: #172e27; box-shadow: 0 -8px 28px rgba(20,35,28,.24); }
.selection-bar > div { display: flex; align-items: center; gap: 7px; }
.selection-bar > div:first-child { justify-content: space-between; margin-bottom: 7px; }
.selection-bar button { min-height: 38px; border: 0; border-radius: 9px; padding: 6px 10px; font-weight: 800; }
.selection-tools { margin-bottom: 7px; }
.selection-tools button { flex: 1; color: #fff; background: rgba(255,255,255,.14); }
.selection-ratings { display: grid !important; grid-template-columns: repeat(4, 1fr); }
.selection-ratings button { font-size: 1.1rem; }
.selection-holds { display: grid !important; grid-template-columns: 1fr 1fr; margin-top: 7px; }
.selection-holds button:first-child { color: #fff; background: var(--hold); }
.selection-holds button:last-child { color: #2d2436; background: #eee8f4; }
.proof-row.selected, .proof-card.selected { position: relative; box-shadow: inset 0 0 0 3px var(--master); background: var(--master-soft); }
.proof-row.selected::after, .proof-card.selected::after { content: "✓"; position: absolute; top: 2px; right: 2px; display: grid; place-items: center; width: 19px; height: 19px; border-radius: 50%; color: #fff; background: var(--master); font-size: .68rem; font-weight: 900; pointer-events: none; }
body.selection-open main { padding-bottom: 225px; }

#hold-range-fields { padding: 11px; border: 1px solid var(--line); border-radius: 11px; background: #fafaf7; }

.today-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-bottom: 12px; }
.today-summary .stat-card { padding: 9px 7px; }
.today-numbers { grid-column: 1 / -1; margin: 2px 0 0; color: var(--muted); font-size: .76rem; line-height: 1.6; }
.batch-list { display: grid; gap: 7px; margin-bottom: 12px; }
.batch-item, .review-item { display: flex; align-items: center; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 11px; }
.batch-item > div, .review-item > div { min-width: 0; flex: 1; }
.batch-item strong, .review-item strong { display: block; }
.batch-item span, .review-item span { color: var(--muted); font-size: .72rem; }
.review-list { display: grid; gap: 7px; }
.review-priority { width: 31px; height: 31px; display: grid; place-items: center; border-radius: 50%; color: #fff; background: var(--accent); font-size: .75rem; font-weight: 900; }
.helper-text { margin-bottom: 10px; color: var(--muted); font-size: .78rem; line-height: 1.6; }
