:root {
  color-scheme: light;
  --ink: #142b28;
  --muted: #506461;
  --deep: #153733;
  --green: #086354;
  --mint: #e0f1eb;
  --line: #dce6e2;
  --paper: #fff;
  --canvas: #f2f6f4;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", Meiryo, system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; color: var(--ink); background: var(--canvas); }
.masthead { background: var(--deep); color: #fff; }
.masthead-inner, nav, main { width: min(100%, 1220px); margin: auto; }
.masthead-inner { padding: 14px max(24px, env(safe-area-inset-right)) 14px max(24px, env(safe-area-inset-left)); }
.masthead-inner, .brand, .device-status, .actions, .spread, .section-heading { display: flex; align-items: center; gap: 10px; }
.masthead-inner, .spread { justify-content: space-between; }
.brand { font-size: 1.15rem; font-weight: 600; }
.brand strong { font-weight: 800; }
.brand img { border-radius: 10px; }
.device-status { font-size: .875rem; flex-wrap: wrap; justify-content: flex-end; }
.device-status span:empty { display: none; }
#offline-status { padding: 5px 9px; border-radius: 6px; color: #e0faf1; background: #24564d; }
nav { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 10px 24px 0; }
nav button { color: var(--muted); background: transparent; border-radius: 8px; }
nav button[aria-current="page"], .switches button[aria-pressed="true"] { background: var(--mint); color: #064c40; }
main { padding: 22px 24px max(26px, env(safe-area-inset-bottom)); }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(1.5rem, 3vw, 2rem); line-height: 1.25; margin: 0 0 16px; }
h2 { font-size: 1.2rem; margin-bottom: 12px; }
h3 { font-size: 1rem; }
p { line-height: 1.6; }
.muted, .hint { color: var(--muted); }
.hint { font-size: .875rem; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 17px; margin-bottom: 14px; min-width: 0; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: end; }
.context { grid-template-columns: minmax(150px, .55fr) minmax(180px, 1fr); }
.wide { grid-column: 1 / -1; }
.entry-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr); gap: 14px; }
.entry-layout > section { align-self: start; }
label { display: grid; gap: 5px; min-width: 0; font-size: .875rem; font-weight: 700; }
button, input, select { font: inherit; }
button { min-height: 46px; border: 1px solid transparent; border-radius: 8px; padding: 8px 13px; background: #edf3f0; color: var(--deep); font-weight: 700; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--green); color: #fff; }
button.danger { color: #8b2727; background: #fbebea; }
button.quiet { background: transparent; color: var(--green); border-color: var(--line); }
input, select { width: 100%; min-width: 0; min-height: 48px; padding: 8px 10px; border: 1px solid #a9bdb7; border-radius: 8px; font-size: 1rem; color: var(--ink); background: #fff; }
input[type="date"] { max-width: 100%; }
input:read-only { background: #f1f5f3; }
:focus-visible { outline: 3px solid #66b9a6; outline-offset: 2px; }
.actions, .switches, .section-heading { flex-wrap: wrap; }
.switches { display: flex; gap: 6px; margin-bottom: 12px; }
.spaced { margin-top: 12px; }
.amount { font-size: clamp(1.4rem, 3.2vw, 1.9rem); font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.quantity button { min-width: 48px; }
.quantity [aria-pressed="true"] { border-color: var(--green); background: var(--mint); }
.material-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.material-list button { text-align: left; overflow-wrap: anywhere; background: #f6f9f7; border-color: var(--line); padding: 9px 10px; }
.material-list button[aria-pressed="true"] { border-color: var(--green); background: var(--mint); }
.material-list strong, .material-list small { display: block; }
.material-list small { color: var(--muted); margin-top: 4px; font-size: .8125rem; }
.notice { border-radius: 8px; padding: 10px 13px; background: #fff1d2; color: #674602; margin-bottom: 12px; }
.notice:last-child { margin-bottom: 0; }
.empty { padding: 22px 4px; color: var(--muted); text-align: center; }
.entries, .master-list { list-style: none; margin: 0; padding: 0; }
.entries li, .master-list li { border-top: 1px solid var(--line); padding: 10px 0; }
.entries li:first-child, .master-list li:first-child { margin-top: 8px; }
.entries p, .master-list p { overflow-wrap: anywhere; }
.entries .spread, .master-list .spread { gap: 12px; }
.entries .spread > :first-child, .master-list .spread > :first-child { min-width: 0; }
.tablewrap { overflow-x: auto; margin-top: 10px; }
table { border-collapse: collapse; width: 100%; text-align: left; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
th { background: #e9f2ee; font-size: .875rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap, td.num { white-space: nowrap; }
tfoot { font-weight: 800; }
.report-filters { display: flex; align-items: end; gap: 10px; flex-wrap: wrap; }
.report-filters label { flex: 1 1 180px; }
details { margin-top: 8px; }
summary { min-height: 44px; padding: 12px 0; cursor: pointer; color: var(--green); font-weight: 700; }
#toast { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); width: max-content; max-width: 92vw; padding: 12px 17px; border-radius: 8px; background: var(--deep); color: white; box-shadow: 0 6px 24px #0d292b35; z-index: 2; pointer-events: none; }

@media (max-width: 790px) {
  .entry-layout { grid-template-columns: 1fr; }
  .material-list { grid-template-columns: repeat(auto-fit, minmax(min(145px, 100%), 1fr)); }
}

@media (max-width: 520px) {
  .masthead-inner, nav, main { padding-left: 10px; padding-right: 10px; }
  .masthead-inner { align-items: flex-start; }
  .brand { font-size: 1rem; }
  .brand img { width: 34px; height: 34px; }
  .device-status { gap: 4px; font-size: .75rem; }
  nav { gap: 2px; }
  nav button { padding: 6px 1px; font-size: .875rem; }
  main { padding-top: 16px; }
  .card { padding: 12px; }
  .context { grid-template-columns: minmax(0, 1fr); }
}

@page { size: A4 portrait; margin: 12mm; }
@media print {
  body { background: white; color: black; font-size: 10pt; }
  header, nav, .no-print, #toast, button { display: none !important; }
  main, .card, .tablewrap { margin: 0; padding: 0; width: auto; max-width: none; border: 0; overflow: visible; }
  h1 { font-size: 17pt; }
  .amount { font-size: 13pt; }
  thead { display: table-header-group; }
  tfoot { display: table-row-group; }
  tr { break-inside: avoid; }
  th, td { border: 1px solid #818181; padding: 5px; }
}
