:root {
  --navy: #0d1b2a;
  --gold: #c9a84c;
  --bg: #f6f6f4;
  --card: #ffffff;
  --border: #d8d8d8;
  --mid: #555;
  --dark: #1a1a1a;
  --green: #2d7d46;
  --amber: #c27a00;
  --red: #b02a37;
  --blue: #1155cc;
  --teal: #00798c;
  --purple: #663399;
  --shadow: 0 2px 12px rgba(0,0,0,.06);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--dark);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

header.topbar {
  background: var(--navy);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
header.topbar .brand {
  color: var(--gold);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: .04em;
}
header.topbar .who { font-size: 13px; opacity: .85; }
header.topbar a { color: #fff; }
header.topbar .right { display: flex; gap: 14px; align-items: center; }

main { max-width: 920px; margin: 0 auto; padding: 16px; }
main.full { max-width: 1200px; }

h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 16px; margin: 18px 0 8px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 200px; }

label { display: block; font-size: 12px; color: var(--mid); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-family: inherit;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(13,27,42,.08);
}

button, .btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 8px;
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 14px;
  cursor: pointer;
  font-family: inherit;
}
button.secondary, .btn.secondary {
  background: #fff; color: var(--navy); border: 1px solid var(--navy);
}
button.gold, .btn.gold { background: var(--gold); color: var(--navy); }
button.danger, .btn.danger { background: var(--red); }
button:disabled, .btn:disabled { opacity: .5; cursor: not-allowed; }

.muted { color: var(--mid); font-size: 13px; }
.error { color: var(--red); font-size: 13px; }
.ok    { color: var(--green); font-size: 13px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { font-size: 12px; color: var(--mid); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .04em;
  background: #eee; color: #333;
}
.badge.draft     { background: #fef3c7; color: #92400e; }
.badge.submitted { background: #dbeafe; color: #1e40af; }
.badge.signed    { background: #d1fae5; color: #065f46; }
.badge.void      { background: #f3f4f6; color: #4b5563; }

.section-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 6px;
  color: #fff; font-size: 12px; font-weight: 600;
  margin-right: 6px; margin-bottom: 6px;
}

/* Inspection page */
.section { margin-bottom: 22px; }
.section-header {
  background: var(--navy); color: #fff;
  padding: 10px 12px; border-radius: var(--radius) var(--radius) 0 0;
  font-weight: 600; font-size: 15px;
  display: flex; justify-content: space-between; align-items: center;
}
.section-body {
  background: #fff;
  border: 1px solid var(--border); border-top: 0;
  border-radius: 0 0 var(--radius) var(--radius);
}
.item-row {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
/* Per-row "✓ saved" flash. Hidden by default; .flash class fires the
   animation. The keyframes restart by toggling the class (with a forced
   reflow in JS). */
.item-row .save-indicator {
  position: absolute;
  top: 8px; right: 10px;
  color: var(--green);
  font-size: 11px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
}
.item-row .save-indicator.flash {
  animation: snagweb-saved 1.6s ease-out;
}
@keyframes snagweb-saved {
  0%   { opacity: 0; transform: translateY(-4px); }
  15%  { opacity: 1; transform: translateY(0); }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}
.item-row:last-child { border-bottom: 0; }
.item-row .label { font-size: 15px; color: var(--dark); font-weight: 500; margin-bottom: 6px; }
.item-row .label-ja { font-size: 12px; color: var(--mid); margin-bottom: 8px; }
.item-row .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.item-row .controls.inv { grid-template-columns: 90px 90px 1fr; }
.item-row .photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.item-row .photos img {
  width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border);
}
/* Photo upload is intentionally tertiary: a small dashed tile that sits beside
   any existing thumbnails. Looks like "you can add one if you want", not "next
   step". */
.item-row .photo-add-tile {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: var(--mid);
  font-size: 20px; line-height: 1;
  background: transparent;
  cursor: pointer;
}
.item-row .photo-add-tile:hover { border-color: var(--navy); color: var(--navy); }

/* baseline mini-card on move-out rows */
.baseline {
  background: #f9fafb;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  font-size: 12px;
}
.baseline .b-label { color: var(--mid); margin-bottom: 4px; }
.baseline .b-photos { display: flex; gap: 4px; flex-wrap: wrap; }
.baseline .b-photos img { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; cursor: zoom-in; }

/* Photo preview overlay — fullscreen lightbox triggered by clicking a thumbnail. */
.photo-preview {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.photo-preview img {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}
.photo-preview .pp-close {
  position: absolute; top: 12px; right: 16px;
  width: 36px; height: 36px;
  background: rgba(255,255,255,0.15);
  color: #fff; border: 0; border-radius: 50%;
  font-size: 22px; line-height: 1; cursor: pointer;
}
.photo-preview .pp-close:hover { background: rgba(255,255,255,0.25); }
.photo-preview .pp-delete {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #b91c1c; color: #fff; border: 0;
  padding: 10px 18px; border-radius: 6px;
  font-size: 14px; cursor: pointer;
}
.photo-preview .pp-delete:hover { background: #991b1b; }

/* Fullscreen signature pad overlay.
   Canvas fills almost the whole viewport; bar pinned at the bottom. */
.sig-overlay {
  position: fixed; inset: 0;
  background: #f3f4f6;
  z-index: 1000;
  display: flex; flex-direction: column;
}
.sig-overlay .sig-hint {
  padding: 10px 16px;
  font-size: 13px; color: var(--mid);
  background: #fff;
  border-bottom: 1px solid var(--border);
}
.sig-overlay .sig-canvas {
  flex: 1;
  display: block;
  background: #fff;
  margin: 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  touch-action: none;
  cursor: crosshair;
  min-height: 0;
}
.sig-overlay .sig-bar {
  display: flex; gap: 10px; padding: 12px 16px;
  background: #fff;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}
.sig-overlay .sig-bar button { padding: 12px 20px; font-size: 15px; }
.sig-overlay .sig-hint { font-size: 14px; color: var(--dark); line-height: 1.4; }

/* Pre-signature notice shown in the Signatures card and inside the pad overlay. */
.sign-notice {
  background: #fdf6e3;
  border: 1px solid var(--gold, #c9a84c);
  border-radius: 6px;
  padding: 12px 14px;
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--dark);
}
.sign-notice .sign-notice-title {
  font-weight: 600; color: var(--navy, #0d1b2a);
  margin-bottom: 4px;
}

/* Login */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: var(--navy);
}
.login-card {
  max-width: 360px; width: 100%;
  background: #fff; padding: 24px; border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-card h1 { color: var(--navy); margin: 0 0 4px; font-size: 22px; }
.login-card .sub { color: var(--mid); font-size: 13px; margin-bottom: 18px; }

/* Signature pad */
.sig-pad {
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #fff;
  width: 100%;
  height: 160px;
  touch-action: none;
}

@media (max-width: 600px) {
  main { padding: 12px; }
  .item-row .controls { grid-template-columns: 1fr; }
  .item-row .controls.inv { grid-template-columns: 1fr 1fr; }
}
