:root {
  color-scheme: light;
  --ink: #18201e;
  --muted: #62706b;
  --line: #d8e2dc;
  --paper: #fbfdfb;
  --panel: #ffffff;
  --accent: #147d64;
  --accent-strong: #0a5e4a;
  --accent-soft: #dff3ec;
  --amber: #b86d16;
  --rose: #b13d4a;
  --shadow: 0 18px 45px rgba(24, 32, 30, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(20, 125, 100, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(184, 109, 22, 0.12), transparent 32%),
    var(--paper);
  color: var(--ink);
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", Meiryo, system-ui, sans-serif;
}

html {
  scroll-behavior: smooth;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 0 26px;
}

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

.brand-mark {
  width: 64px;
  height: 64px;
  flex: 0 0 auto;
  fill: var(--accent-soft);
  stroke: var(--accent-strong);
  stroke-width: 3;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.8rem, 3vw, 3.1rem);
  line-height: 1.1;
}

h2 {
  font-size: 1.25rem;
}

h3 {
  font-size: 1.05rem;
}

h4 {
  font-size: 0.96rem;
}

.summary {
  min-width: 190px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.summary span {
  display: block;
  font-weight: 800;
}

.summary-track,
.bag-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eeeb;
}

.summary-track {
  margin-top: 10px;
}

.summary-track span,
.bag-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.control-band {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.control-band summary {
  display: none;
}

.control-content {
  display: block;
}

.summary-hint {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.section-head p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.55;
}

.section-head.compact {
  margin-bottom: 14px;
}

.actions {
  display: flex;
  gap: 8px;
}

.icon-button,
.remove-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
}

.danger {
  color: var(--rose);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  align-items: end;
}

.stock-tools {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(223, 243, 236, 0.5);
}

.stock-tools button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--accent-strong);
  padding: 0 14px;
  font-weight: 800;
}

.stock-tools .secondary-danger {
  color: var(--rose);
}

.stock-tools p {
  align-self: center;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  white-space: nowrap;
}

label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 9px 11px;
}

input[type="file"] {
  padding: 8px;
}

.image-field {
  min-width: 0;
}

.image-preview {
  display: grid;
  width: 72px;
  height: 44px;
  place-items: center;
  overflow: hidden;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(20, 125, 100, 0.24);
  outline-offset: 2px;
}

.primary-button,
.bag-form button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 0 18px;
  font-weight: 800;
}

.primary-button {
  min-width: 86px;
}

.organizer-forms {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(360px, 1.2fr);
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.bag-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(170px, 0.8fr) auto;
  gap: 12px;
  align-items: end;
}

#caseForm {
  grid-template-columns: minmax(140px, 0.75fr) minmax(180px, 1fr) minmax(170px, 0.8fr) auto;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.bag-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.bag-card,
.packed-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.bag-card {
  padding: 18px;
}

.packed-panel {
  position: sticky;
  top: 18px;
  padding: 18px;
}

.bag-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.bag-card-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--rose);
  font-weight: 800;
}

.bag-card-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.bag-photo {
  display: grid;
  width: 72px;
  height: 72px;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef4f1;
}

.bag-photo::before,
.case-photo::before,
.item-thumb::before {
  content: var(--fallback-text, "IMG");
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 800;
}

.bag-photo.has-image::before,
.case-photo.has-image::before,
.item-thumb.has-image::before {
  content: "";
}

.bag-photo img,
.case-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.item-list,
.packed-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.case-list {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.case-section {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 253, 251, 0.74);
}

.case-section.direct-case {
  background: rgba(255, 255, 255, 0.58);
}

.case-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.case-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.case-photo {
  display: grid;
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef4f1;
}

.case-head p {
  display: grid;
  gap: 3px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.84rem;
}

.location-line {
  display: block;
  color: var(--accent-strong);
  font-weight: 800;
}

.rank-badge {
  display: inline-block;
  margin-right: 6px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #edf6f2;
  color: var(--accent-strong);
  font-size: 0.75rem;
  font-weight: 800;
}

.item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.check-label {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}

.item-thumb {
  display: grid;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef4f1;
}

.item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.check-label input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.fake-check {
  display: grid;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid var(--accent);
  border-radius: 7px;
}

.check-label input:checked + .fake-check {
  background: var(--accent);
}

.check-label input:checked + .fake-check::after {
  content: "";
  width: 11px;
  height: 6px;
  border: solid #fff;
  border-width: 0 0 3px 3px;
  transform: rotate(-45deg) translate(1px, -1px);
}

.item-copy {
  min-width: 0;
}

.item-copy strong,
.item-copy small {
  display: block;
}

.item-copy strong {
  overflow-wrap: anywhere;
}

.item-copy small {
  display: grid;
  gap: 3px;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
}

.remove-button {
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  color: var(--rose);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.image-upload {
  display: inline-grid;
  min-width: 44px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  padding: 0 8px;
  cursor: pointer;
}

.image-upload span {
  display: inline;
  margin: 0;
  color: inherit;
  font-size: inherit;
}

.image-upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.empty-state {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  line-height: 1.55;
  background: rgba(255, 255, 255, 0.6);
}

.packed-entry {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 4px 10px;
  padding: 11px;
  border-radius: 8px;
  background: var(--accent-soft);
}

.packed-entry .item-thumb {
  width: 46px;
  height: 46px;
  grid-row: span 3;
  background: rgba(255, 255, 255, 0.64);
}

.packed-entry strong {
  overflow-wrap: anywhere;
}

.packed-entry small {
  display: grid;
  gap: 3px;
  color: var(--accent-strong);
}

.packed-entry button {
  justify-self: start;
  margin-top: 4px;
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  padding: 0;
  font-weight: 800;
}

.packed-entry strong,
.packed-entry small,
.packed-entry button {
  grid-column: 2;
}

@media (max-width: 940px) {
  .topbar,
  .section-head {
    flex-direction: column;
  }

  .summary {
    width: 100%;
  }

  .form-grid,
  .stock-tools,
  .layout,
  .bag-list,
  .organizer-forms,
  #caseForm {
    grid-template-columns: 1fr;
  }

  .packed-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  body {
    background: var(--paper);
  }

  .app-shell {
    width: 100%;
    padding: 10px 10px 24px;
  }

  .topbar {
    gap: 12px;
    padding: 10px 0 12px;
  }

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

  .brand-mark {
    width: 44px;
    height: 44px;
  }

  .eyebrow {
    font-size: 0.68rem;
  }

  h1 {
    font-size: 1.55rem;
  }

  .summary {
    min-width: 0;
    padding: 10px 12px;
    box-shadow: none;
  }

  .control-band {
    padding: 0;
    overflow: hidden;
  }

  .control-band summary {
    display: flex;
    min-height: 52px;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    color: var(--ink);
    font-weight: 900;
    list-style: none;
  }

  .control-band summary::-webkit-details-marker {
    display: none;
  }

  .control-band summary::after {
    content: "+";
    display: grid;
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--accent-strong);
  }

  .control-band[open] summary::after {
    content: "-";
  }

  .control-content {
    padding: 0 12px 12px;
  }

  .section-head {
    gap: 10px;
    margin-bottom: 12px;
  }

  .section-head p {
    font-size: 0.9rem;
  }

  .actions {
    width: 100%;
  }

  .icon-button {
    flex: 1 1 0;
    height: 44px;
  }

  input,
  select,
  .stock-tools button,
  .primary-button,
  .bag-form button {
    min-height: 48px;
    font-size: 16px;
  }

  .stock-tools {
    gap: 8px;
    padding: 10px;
  }

  .stock-tools p {
    justify-self: start;
  }

  .image-preview {
    width: 100%;
    height: 56px;
  }

  .control-band,
  .bag-card,
  .packed-panel {
    border-radius: 8px;
    box-shadow: none;
  }

  .bag-form {
    grid-template-columns: 1fr;
  }

  .layout {
    gap: 12px;
    margin-top: 12px;
  }

  .bag-list,
  .case-list,
  .item-list,
  .packed-list {
    gap: 10px;
  }

  .bag-card,
  .packed-panel {
    padding: 12px;
  }

  .bag-card-head {
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 10px;
  }

  .bag-card-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .bag-card-actions .image-upload,
  .bag-card-actions .text-button,
  .case-actions .image-upload,
  .case-actions .text-button {
    flex: 1 1 0;
    min-height: 40px;
    text-align: center;
  }

  .bag-photo {
    width: 58px;
    height: 58px;
  }

  .case-section {
    padding: 10px;
  }

  .case-head {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    gap: 8px;
  }

  .case-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .case-photo {
    width: 48px;
    height: 48px;
  }

  .item-row {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr);
    align-items: stretch;
    gap: 8px;
    min-height: 72px;
    padding: 10px;
  }

  .item-thumb {
    width: 46px;
    height: 46px;
  }

  .check-label {
    gap: 8px;
    align-self: stretch;
  }

  .fake-check {
    width: 28px;
    height: 28px;
  }

  .row-actions {
    grid-column: 1 / -1;
    justify-content: stretch;
  }

  .row-actions .image-upload,
  .row-actions .remove-button {
    flex: 1 1 0;
    min-height: 40px;
  }

  .remove-button {
    width: auto;
  }

  .packed-entry {
    grid-template-columns: 44px minmax(0, 1fr);
  }
}
