:root {
  --bg: #eef1f5; --card: #fff; --ink: #1b2330; --muted: #6b7686; --line: #d5dbe3;
  --pri: #1f5fbf; --pri-ink: #fff; --ok: #1f8a4c; --warn: #c77700; --err: #c62828;
  --blue-lb: #dcebf9; --pink-lb: #f8dde3; --on: #1f5fbf; --on-bg: #e3edfb;
  --r: 12px; --h: 46px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", sans-serif;
  background: var(--bg); color: var(--ink); font-size: 16px; line-height: 1.45; }
a { color: var(--pri); text-decoration: none; }
small { font-size: .78em; }
.muted { color: var(--muted); }
.red { color: var(--err); }
.center { text-align: center; }
.err { color: var(--err); }
.hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
.mt { margin-top: 12px; }

/* ---------- top bar ---------- */
.top { position: sticky; top: 0; z-index: 20; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; background: #16325c; color: #fff; }
.top .tl { justify-self: start; } .top .tr { justify-self: end; display: flex; gap: 8px; align-items: center; }
.top .tt { font-weight: 700; font-size: 17px; text-align: center; line-height: 1.2; }
.top .tt small { display: block; font-weight: 400; opacity: .85; font-size: 12px; }
.top .btn.ghost { color: #fff; border-color: rgba(255,255,255,.4); background: transparent; }
.save-state { font-size: 12px; opacity: .85; min-width: 4em; text-align: right; }
.save-state.dirty { color: #ffd479; opacity: 1; }

.stick { position: sticky; top: 0; z-index: 20; }
.stick .top { position: static; }
.tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: #fff; border-bottom: 1px solid var(--line); }
.tabs button { height: 48px; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs button.on { color: var(--pri); border-bottom-color: var(--pri); }

.wrap { max-width: 1100px; margin: 0 auto; padding: 14px 14px 30px; }
.wrap.narrow { max-width: 520px; }
.spacer { height: 90px; }

/* ---------- cards / fields ---------- */
.card { background: var(--card); border-radius: var(--r); padding: 14px 16px; margin-bottom: 14px; box-shadow: 0 1px 2px rgba(20,30,50,.06); }
.card h3 { margin: -2px 0 12px; font-size: 15px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  padding-left: 8px; border-left: 4px solid #7fb2e5; }
.card h3 .h-right { font-weight: 400; font-size: 13px; color: var(--muted); }
.card h4 { font-size: 14px; margin: 16px 0 8px; }
.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld .lb { font-size: 12px; color: var(--muted); font-weight: 600; }
.fld.inline { flex-direction: row; align-items: center; gap: 6px; }
.fld.span2 { grid-column: span 2; }
.g { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 8px; align-items: center; }
.row .in { flex: 1; } .row .qty { flex: 0 0 90px; }
.unit { color: var(--muted); font-size: 14px; white-space: nowrap; }

.in { width: 100%; height: var(--h); border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font: inherit; font-size: 17px;
  background: #fbfcfe; color: var(--ink); -webkit-appearance: none; appearance: none; }
.in:focus { outline: 2px solid #8ab4ee; border-color: var(--pri); background: #fff; }
.in:disabled { background: #f1f3f6; color: #7a8594; }
.in.ta { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.in.time { min-width: 0; text-align: center; }
.in.qty { width: 90px; flex: 0 0 90px; text-align: center; }
.in.qty2 { width: 110px; }
select.in { background-image: linear-gradient(45deg, transparent 50%, #889 50%), linear-gradient(135deg, #889 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 28px; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 15px; }
.rng { display: flex; align-items: center; gap: 6px; } .rng .in { flex: 1; } .tilde { color: var(--muted); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--h); padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 14px; }
.btn.big { height: 54px; font-size: 18px; }
.btn.block { display: flex; width: 100%; margin-bottom: 8px; }
.btn.primary { background: var(--pri); color: #fff; border-color: var(--pri); }
.btn.warn { background: #fff4e0; color: #8a4f00; border-color: #f0c170; }
.btn.danger { color: var(--err); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; }
.icon-btn { width: 40px; height: 40px; border: 0; background: none; color: #a0a8b4; font-size: 18px; flex: 0 0 40px; }

/* segmented / chips / checks */
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.seg button { min-width: 64px; height: var(--h); padding: 0 14px; border: 0; border-right: 1px solid var(--line); background: #fff; font: inherit; font-size: 17px; color: var(--ink); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--on); color: #fff; font-weight: 700; }
.seg.big button { min-width: 72px; font-size: 20px; height: 54px; }
.seg.sym button { min-width: 54px; font-size: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { height: 42px; padding: 0 16px; border-radius: 21px; border: 1px solid var(--line); background: #fff; font: inherit; font-size: 16px; color: var(--ink); }
.chip.on { background: var(--on); color: #fff; border-color: var(--on); font-weight: 700; }
.chk { display: inline-flex; align-items: center; gap: 8px; min-height: var(--h); border: 0; background: none; font: inherit; color: var(--ink); padding: 0; text-align: left; }
.chk .box { width: 30px; height: 30px; border: 2px solid #9aa5b4; border-radius: 7px; flex: 0 0 30px; display: grid; place-items: center; background: #fff; }
.chk.on .box { background: var(--ok); border-color: var(--ok); }
.chk.on .box::after { content: "✔"; color: #fff; font-size: 18px; }
.chk:disabled { opacity: .55; }
.tri { width: 56px; height: 44px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 22px; font-weight: 700; }
.tri.ok { background: #e3f5ea; color: var(--ok); border-color: #9fd6b3; }
.tri.ng { background: #fde8e8; color: var(--err); border-color: #f0a8a8; }
.stp { display: inline-flex; align-items: center; }
.stp button { width: 42px; height: var(--h); border: 1px solid var(--line); background: #f5f7fa; font-size: 20px; }
.stp button:first-child { border-radius: 10px 0 0 10px; } .stp button:last-child { border-radius: 0 10px 10px 0; }
.stp .in { width: 58px; border-radius: 0; text-align: center; border-left: 0; border-right: 0; padding: 0 4px; }

/* badges */
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 700; background: #e8ebef; color: #555; white-space: nowrap; }
.st-instructed { background: #e3edfb; color: #1f5fbf; }
.st-submitted { background: #fff1d6; color: #8a5a00; }
.st-approved { background: #dff3e6; color: #1f7a45; }

/* ---------- login ---------- */
body.login-mode { background: linear-gradient(160deg, #16325c, #2d5b9a); min-height: 100vh; }
.login { max-width: 380px; margin: 12vh auto 0; background: #fff; padding: 28px; border-radius: 16px; display: grid; gap: 16px; }
.login h1 { margin: 0 0 6px; text-align: center; font-size: 22px; }
.logo { display: inline-block; background: #bcd9f3; padding: 0 8px; margin-right: 8px; border-radius: 4px; }

/* ---------- list ---------- */
.filters { display: grid; grid-template-columns: 1.6fr 1.4fr .8fr; gap: 12px; align-items: end; }
.quick-range { grid-column: 1 / -1; display: flex; gap: 8px; }
.csv-bar { display: flex; gap: 8px; align-items: center; margin: 0 0 12px; flex-wrap: wrap; font-size: 14px; }
.dhead { font-size: 15px; margin: 18px 4px 8px; color: #334; }
.dhead .today { background: var(--pri); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 10px; margin-left: 8px; vertical-align: middle; }
.item { display: flex; align-items: center; background: #fff; border-radius: var(--r); margin-bottom: 8px; box-shadow: 0 1px 2px rgba(20,30,50,.06); }
.item-main { flex: 1; display: grid; grid-template-columns: auto auto 1fr; grid-template-rows: auto auto; column-gap: 10px; padding: 12px 14px; color: var(--ink); align-items: center; min-width: 0; }
.item-main .site { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-main .meta { grid-column: 3; color: var(--muted); font-size: 13px; }
.shift { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: #fff7cc; color: #6b5800; }
.shift.night { background: #2b3350; color: #fff; }
.item-act { display: flex; gap: 6px; padding-right: 10px; align-items: center; }
.item-act .dot { color: var(--warn); }
.draft-note { display: block; background: #fff4e0; color: #8a4f00; }

/* ---------- editor ---------- */
.hdr-grid { display: grid; grid-template-columns: 170px auto 1fr 1.4fr; gap: 12px; }
.hdr-grid .w-addr { grid-column: 1 / -1; }
.hdr-sum { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
.hdr-sum-txt { flex: 1 1 0; min-width: 0; font-weight: 600; line-height: 1.5; }
.hdr-sum-txt .sep { color: var(--muted); font-weight: 400; }
.hdr-missing { flex-basis: 100%; background: #fde8e8; color: var(--err); border: 1px solid #f0a8a8; border-radius: 8px; padding: 8px 12px; font-weight: 700; }
.lock-note { background: #dff3e6; color: #1f7a45; padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; font-weight: 600; }
.editor.locked .card { opacity: .92; }
.actbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
  padding: 10px 14px calc(env(safe-area-inset-bottom) + 10px); background: rgba(255,255,255,.96); border-top: 1px solid var(--line); backdrop-filter: blur(8px); }
.actbar .btn { min-width: 110px; }

/* workers */
.quick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.quick .lb { font-size: 12px; color: var(--muted); }
.quick .chip { height: 36px; font-size: 15px; }
.wrow2 { display: flex; gap: 10px; align-items: center; padding: 5px 0; border-bottom: 1px dashed #e6e9ee; }
.wrow2 .no { flex: 0 0 38px; font-size: 13px; color: var(--muted); text-align: center; font-weight: 700; }
.wrow2 .grow { flex: 1; }
.wrow2 .fld.inline .in { width: 120px; }
.wrow2 .fld.inline .lb { font-weight: 400; }

/* 外注 */
.grp { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.gname { flex: 0 0 26px; font-weight: 700; padding-top: 10px; color: var(--muted); }
.comps { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.ccell { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 4px 8px; background: #f7f9fb; border-radius: 10px; }
.ccell > span:first-child { flex: 1; font-weight: 600; }

/* vehicles */
.vrow { border: 1px solid #e3e7ec; border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.route { display: flex; align-items: center; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.route .lb { font-size: 12px; color: var(--muted); font-weight: 600; width: 100%; }
.route .in { flex: 1 1 120px; }
.arr { color: var(--muted); }
.office-row { margin-top: 10px; padding-top: 10px; border-top: 1px dashed #e3e7ec; }
.office-row .lb, .fld .lb:has(+ [disabled]) { }
.stamp { color: #c62828; border-color: #f0a8a8; }

/* 指示書 tools */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; margin-bottom: 10px; align-items: center; }
.legend i { display: inline-block; width: 22px; height: 5px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin-bottom: 10px; }
.trow { display: flex; gap: 6px; align-items: center; }
.trow .gbar { width: 5px; align-self: stretch; border-radius: 3px; background: var(--gc); flex: 0 0 5px; }
.trow .grow { flex: 1; min-width: 0; }
.trow .qty { width: 64px; flex: 0 0 64px; }
.trow .sel { width: 104px; flex: 0 0 104px; font-size: 14px; padding-left: 8px; }
.ok-chk .box { width: 28px; height: 28px; }
.cons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 20px; }
.crow { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.crow .cname { flex: 1; }
.wrow { display: grid; grid-template-columns: 1fr auto 1fr 90px; gap: 10px; margin-top: 10px; align-items: end; }

/* KY */
.ky { border: 1px solid #e3e7ec; border-radius: 10px; margin-bottom: 8px; }
.ky.on { border-color: #9cc0ee; background: #f7faff; }
.ky-head { display: flex; align-items: center; gap: 10px; padding: 4px 12px; min-height: 52px; }
.ky-text { flex: 1; font-size: 16px; }
.ky-head .grow { flex: 1; }
.ky-risk { display: flex; align-items: center; gap: 6px; min-width: 120px; justify-content: flex-end; }
.ky-risk small { color: var(--muted); }
.ky-body { padding: 4px 12px 12px 52px; display: grid; gap: 10px; }
.risk { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; color: #fff; font-size: 17px; }
.risk.r1 { background: #3d9a5f; } .risk.r2 { background: #88b04b; } .risk.r3 { background: #e0a100; } .risk.r4 { background: #e56a1c; } .risk.r5 { background: #c62828; }
.parts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; margin-top: 10px; }
.prow { display: flex; gap: 8px; align-items: center; }
.prow .no { width: 22px; color: var(--muted); font-size: 13px; text-align: right; }
.prow .grow { flex: 1; }
.ref summary { font-weight: 700; cursor: pointer; padding: 4px 0; }
.reftables { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.reftables table, .heat-tbl { border-collapse: collapse; width: 100%; font-size: 13px; }
.reftables th, .reftables td, .heat-tbl th, .heat-tbl td { border: 1px solid #c9d0da; padding: 5px 7px; }
.reftables th { background: #f3ead6; }
.steps { font-size: 14px; padding-left: 22px; }
.steps li { margin: 3px 0; }
.steps b { color: var(--err); }

/* 点検 */
.ctbl { border: 1px solid #e3e7ec; border-radius: 10px; overflow: hidden; }
.ctbl .ch, .ctbl .cr { display: grid; grid-template-columns: 1fr 76px 76px; align-items: center; gap: 0; }
.ctbl .ch { background: #f3f5f8; font-size: 13px; font-weight: 700; color: var(--muted); padding: 8px 12px; }
.ctbl .ch span:not(:first-child) { text-align: center; }
.ctbl .cr { padding: 5px 12px; border-top: 1px solid #eef0f3; }
.ctbl .cr .tri { justify-self: center; }
.ctbl .foot .btn { justify-self: center; padding: 0 6px; font-size: 12px; }
.mrow { display: grid; grid-template-columns: 90px 140px 110px 110px 1fr; gap: 10px; align-items: end; padding: 8px 0; border-bottom: 1px dashed #e6e9ee; }
.mlabel { font-weight: 700; padding-bottom: 12px; }
.mres { padding-bottom: 10px; }
.heat { display: inline-block; padding: 6px 10px; border-radius: 8px; font-size: 14px; font-weight: 700; }
.heat.danger { background: #d32f2f; color: #fff; } .heat.warn { background: #f2b227; color: #3b2a00; } .heat.ok { background: #e3f5ea; color: #1f7a45; }
.heat-tbl .danger td { background: #d32f2f; color: #fff; } .heat-tbl .warn td { background: #f2b227; }
.warn-line { color: var(--err); font-weight: 700; text-align: center; }
.sev div { padding: 8px 10px; margin: 4px 0; border-radius: 6px; font-size: 14px; }
.sev b { margin-right: 8px; }
.sev .s1 { background: #fff5b8; } .sev .s2 { background: #f7c677; } .sev .s3 { background: #e8904d; }
.sev .call { color: var(--err); font-weight: 700; }

.audit { font-size: 13px; color: var(--muted); } .audit summary { cursor: pointer; }

/* sheet menu */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; display: flex; justify-content: flex-start; }
.sheet { background: #fff; width: 300px; max-width: 85vw; padding: calc(env(safe-area-inset-top) + 20px) 16px 16px; height: 100%; overflow: auto; }

/* masters / users */
.masters { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.masters .card { margin: 0; } .masters .ta { margin-bottom: 8px; }
.utbl { width: 100%; border-collapse: collapse; }
.utbl th, .utbl td { text-align: left; padding: 8px; border-bottom: 1px solid #eef0f3; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 100px; transform: translate(-50%, 20px); background: #223; color: #fff; padding: 12px 20px; border-radius: 10px;
  opacity: 0; transition: .25s; z-index: 100; max-width: 90vw; font-size: 15px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.ok { background: #1f7a45; } .toast.err { background: #c62828; } .toast.warn { background: #a86300; }

/* ---------- 縦持ちiPad・スマホ ---------- */
@media (max-width: 900px) {
  .hdr-grid { grid-template-columns: 1fr auto; }
  .hdr-grid .w-client, .hdr-grid .w-site { grid-column: span 1; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tools { grid-template-columns: 1fr; }
  .reftables { grid-template-columns: 1fr; }
  .mrow { grid-template-columns: 80px 1fr 90px 90px; }
  .mres { grid-column: 1 / -1; padding: 0; }
}
@media (max-width: 640px) {
  .g2, .g3, .g4, .cons, .parts { grid-template-columns: 1fr; }
  .fld.span2 { grid-column: auto; }
  .hdr-grid { grid-template-columns: 1fr 1fr; } .hdr-grid .w-site, .hdr-grid .w-client { grid-column: 1 / -1; }
  .filters { grid-template-columns: 1fr; }
  .item { flex-direction: column; align-items: stretch; } .item-act { padding: 0 12px 10px; }
  .trow { flex-wrap: wrap; } .trow .grow { flex: 1 1 60%; }
  .wrow { grid-template-columns: 1fr 1fr; }
  .tabs button { font-size: 13px; }
  .actbar .btn { min-width: 0; flex: 1; }
  .top .tt { font-size: 15px; }
}
.ccell > span:first-child { min-width: 0; }
.ccell .in.qty2 { width: 84px; padding: 0 8px; }

/* PDFメール送信ダイアログ */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 60; display: flex; align-items: flex-start; justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) 12px 24px; overflow: auto; }
.modal { background: #fff; border-radius: var(--r); padding: 18px; width: 560px; max-width: 100%; display: flex; flex-direction: column; gap: 12px; }
.modal h3 { margin: 0; font-size: 17px; }
.modal .mchips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -4px; }
.modal .mpages { flex-wrap: wrap; gap: 14px; font-size: 14px; }
.modal .mpages .lb { font-size: 12px; color: var(--muted); font-weight: 600; }
.modal .mact { justify-content: flex-end; }
.modal .err { margin: 0; min-height: 1em; }
