:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --line: #d9dee7;
  --line-soft: #e8ecf2;
  --ink: #1b2534;
  --ink-2: #5a667a;
  --ink-3: #8b95a7;
  --accent: #0b5ea8;
  --accent-soft: #e8f1fa;
  --accent-2: #0f9d76;
  --danger: #c0392b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", Meiryo, system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #10243b;
  color: #fff;
  box-shadow: 0 2px 8px rgba(16, 36, 59, .18);
}

.brand { display: flex; align-items: center; gap: 10px; }

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #e8442e;
  font-weight: 800;
  letter-spacing: .5px;
  font-size: 15px;
}

.brand-text h1 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: .02em; }
.brand-text p { margin: 0; font-size: 11.5px; color: #a9bdd6; }

.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.actions select {
  min-width: 190px;
  max-width: 280px;
  padding: 7px 9px;
  border-radius: 6px;
  border: 1px solid #2a4462;
  background: #17324f;
  color: #fff;
  font-size: 13px;
}

.actions button {
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid #2a4462;
  background: #17324f;
  color: #dbe6f3;
  font-size: 13px;
  cursor: pointer;
}

.actions button:hover { background: #1f4064; }

.actions button.primary {
  background: #e8442e;
  border-color: #e8442e;
  color: #fff;
  font-weight: 700;
}

.actions button.primary:hover { background: #d33a25; }

main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 44%);
  gap: 14px;
  padding: 14px;
  align-items: start;
}

.pane { min-width: 0; }

.form-pane {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.card > h2 {
  margin: 0;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--accent);
  background: var(--accent-soft);
  border-bottom: 1px solid var(--line-soft);
}

.card-body {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 10px;
  padding: 12px;
}

.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field.wide { grid-column: span 2; }
.field.full { grid-column: 1 / -1; }

.field > label {
  font-size: 11.5px;
  color: var(--ink-2);
  font-weight: 600;
}

.field .input-wrap { display: flex; align-items: center; gap: 5px; }

.field input[type="text"],
.field select,
.field textarea {
  width: 100%;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  font-family: inherit;
}

.field input[type="text"]:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 94, 168, .12);
}

.field textarea { resize: vertical; line-height: 1.6; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.chip {
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f7f9fc;
  color: var(--ink-2);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}

.chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.unit { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  grid-column: 1 / -1;
}

.checks label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
}

.checks input { accent-color: var(--accent); margin: 0; }

.checks label:has(input:checked) {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.hint { font-size: 11px; color: var(--ink-3); grid-column: 1 / -1; margin: 0; }

.sheet-pane {
  position: sticky;
  top: 70px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.sheet-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--ink-2);
  background: #f8fafc;
  border-bottom: 1px solid var(--line-soft);
}

.save-state { font-weight: 600; color: var(--accent-2); letter-spacing: 0; }

.sheet-scroll { max-height: calc(100vh - 130px); overflow: auto; padding: 12px; background: #eef1f5; }

.sheet {
  background: #fff;
  color: #111;
  padding: 14px 16px;
  border: 1px solid #cfd6e0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .08);
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  padding-bottom: 8px;
  margin-bottom: 10px;
  border-bottom: 2px solid #111;
}

.sheet-head .t { font-size: 15px; font-weight: 800; letter-spacing: .04em; }
.sheet-head .lot { font-size: 12px; color: #333; }
.sheet-head .lot b { font-size: 22px; letter-spacing: .02em; margin-left: 6px; }

.sheet section { margin-bottom: 9px; }

.sheet h3 {
  margin: 0 0 4px;
  padding: 2px 0 2px 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1em;
  color: #fff;
  background: #34495e;
}

.sheet .grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border-top: 1px solid #999;
  border-left: 1px solid #999;
}

.sheet .cell {
  display: flex;
  flex-direction: column;
  padding: 3px 5px 4px;
  border-right: 1px solid #999;
  border-bottom: 1px solid #999;
  min-height: 40px;
}

.sheet .cell.s2 { grid-column: span 2; }
.sheet .cell.s3 { grid-column: span 3; }

.sheet .k { font-size: 9px; color: #555; letter-spacing: .04em; }

.sheet .v {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.25;
  word-break: break-all;
  white-space: pre-wrap;
}

.sheet .v.big { font-size: 19px; }
.sheet .v.small { font-size: 12.5px; font-weight: 600; }
.sheet .v.empty { color: #c7ccd4; font-weight: 400; }

.sheet .marks { display: flex; flex-wrap: wrap; gap: 4px 10px; padding: 2px 0; }
.sheet .marks span { font-size: 11.5px; color: #888; }
.sheet .marks span.on { color: #111; font-weight: 800; }

.sheet .marks span.on::before { content: "◯ "; }

.sheet .lines { padding: 4px 0; }
.sheet .lines div {
  border-bottom: 1px solid #bbb;
  min-height: 22px;
  font-size: 14px;
  font-weight: 700;
  padding: 1px 2px;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 18px;
  border-radius: 8px;
  background: #10243b;
  color: #fff;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 50;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1180px) {
  .card-body { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .card-body { grid-template-columns: minmax(0, 1fr); }
  .field.wide, .field.full { grid-column: auto; }
}

@media (max-width: 980px) {
  main { grid-template-columns: minmax(0, 1fr); }
  .sheet-pane { position: static; }
  .sheet-scroll { max-height: none; }
}

@media print {
  @page { size: A4 portrait; margin: 8mm; }

  body { background: #fff; }
  .topbar, .form-pane, .sheet-toolbar, .toast { display: none !important; }

  main { display: block; padding: 0; margin: 0; }
  .sheet-pane { position: static; border: 0; border-radius: 0; overflow: visible; }

  .sheet-scroll { max-height: none; overflow: visible; padding: 0; background: #fff; }

  .sheet {
    border: 0;
    box-shadow: none;
    padding: 0;
    font-size: 10.5px;
    line-height: 1.3;
  }

  .sheet-head { padding-bottom: 4px; margin-bottom: 5px; border-bottom-width: 1.5px; }
  .sheet-head .t { font-size: 14px; }
  .sheet-head .lot { font-size: 10px; }
  .sheet-head .lot b { font-size: 20px; }

  .sheet section { margin-bottom: 3px; break-inside: avoid; }
  .sheet h3 { font-size: 8.5px; padding: 1px 0 1px 6px; margin-bottom: 1px; }

  .sheet .k { font-size: 8.5px; }
  .sheet .v { font-size: 10.5px; line-height: 1.25; }
  .sheet .v.big { font-size: 13.5px; }
  .sheet .v.small { font-size: 10px; }
  .sheet .cell { min-height: 19px; padding: 0 4px 1px; }
  .sheet .marks { gap: 3px 10px; }
  .sheet .marks span { font-size: 11px; }
  .sheet .lines div { min-height: 15px; font-size: 10.5px; }
  .sheet h3 { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
