:root {
  color-scheme: light;
  --bg: #f7f8f5;
  --panel: #ffffff;
  --panel-soft: #eef3ee;
  --ink: #17201b;
  --muted: #5a665f;
  --line: #d9dfd9;
  --accent: #1d6f5d;
  --accent-dark: #124c40;
  --warn: #9a5a00;
  --low: #8b3f46;
  --shadow: 0 10px 30px rgba(22, 32, 27, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
  overflow-x: hidden;
}

a {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px clamp(16px, 4vw, 42px);
  background: rgba(247, 248, 245, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  font-size: 1.25rem;
  font-weight: 760;
  text-decoration: none;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.nav a {
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 640;
  text-decoration: none;
  white-space: nowrap;
}

.nav a:hover,
.nav a.active {
  background: var(--panel-soft);
  color: var(--accent-dark);
}

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

.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(247, 248, 245, 0.96);
}

.gate.visible {
  display: grid;
}

.gate-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 20px;
  box-shadow: var(--shadow);
}

.gate-panel h1 {
  font-size: 1.7rem;
}

.gate-error {
  min-height: 1.4em;
  color: var(--low);
  font-weight: 700;
}

.hero {
  display: grid;
  gap: 18px;
  padding: 20px 0 26px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 2px;
  font-size: clamp(2rem, 8vw, 4.9rem);
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.45rem;
}

h3 {
  margin-bottom: 6px;
  font-size: 1.05rem;
}

.subtle {
  color: var(--muted);
}

.search-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  max-width: 860px;
}

.search-input {
  min-width: 0;
  min-height: 64px;
  padding: 0 18px;
  border: 2px solid var(--accent);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 1.3rem;
  outline: none;
}

.search-input:focus {
  box-shadow: 0 0 0 4px rgba(29, 111, 93, 0.18);
}

.button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 720;
  text-decoration: none;
  cursor: pointer;
}

button.secondary,
.button.secondary {
  background: var(--panel);
  color: var(--accent-dark);
}

.answer {
  max-width: 900px;
  padding: 16px 18px;
  border: 1px solid #b7d7cd;
  border-left: 6px solid var(--accent);
  border-radius: 8px;
  background: #f1faf6;
  box-shadow: var(--shadow);
  font-size: 1.1rem;
  font-weight: 690;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.result-list {
  display: grid;
  gap: 12px;
}

.result-card,
.location-card,
.photo-card,
.category-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.result-card {
  display: grid;
  grid-template-columns: 164px 1fr;
  min-height: 154px;
}

.result-thumb,
.location-thumb,
.photo-card img,
.detail-photo {
  width: 100%;
  height: 100%;
  background: var(--panel-soft);
  object-fit: cover;
}

.result-body,
.location-card,
.category-card {
  padding: 14px;
}

.result-title-row,
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.badge {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  background: #dcf0e9;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 760;
  text-transform: uppercase;
}

.badge.medium {
  background: #fff0d7;
  color: var(--warn);
}

.badge.low {
  background: #f8dfe2;
  color: var(--low);
}

.location-line,
.meta-line {
  margin-bottom: 8px;
  color: var(--muted);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 12px;
}

.chip {
  max-width: 100%;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.location-card {
  display: grid;
  grid-template-rows: 160px auto;
  padding: 0;
}

.location-card-body {
  padding: 12px;
}

.location-card h3,
.category-card h3 {
  overflow-wrap: anywhere;
}

.cubby-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.cubby-cell {
  min-width: 0;
  min-height: 168px;
  display: grid;
  grid-template-rows: 82px auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.cubby-cell img {
  width: 100%;
  height: 82px;
  object-fit: cover;
}

.cubby-body {
  min-width: 0;
  padding: 8px;
}

.cubby-bin {
  font-weight: 800;
}

.cubby-title,
.tiny {
  color: var(--muted);
  font-size: 0.83rem;
}

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

.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
  box-shadow: var(--shadow);
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.editor-status {
  min-height: 1.2em;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 700;
}

.editor-group {
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.editor-group-head,
.editor-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.editor-items {
  display: grid;
  gap: 10px;
}

.editor-item {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

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

.field-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 700;
}

.field-span {
  grid-column: 1 / -1;
}

.editor-textarea {
  min-height: 92px;
  resize: vertical;
}

.editor-group-actions {
  display: flex;
  justify-content: flex-start;
  margin-top: 10px;
}

.photo-stack {
  display: grid;
  gap: 10px;
}

.detail-photo-card {
  padding: 0;
  overflow: hidden;
}

.photo-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0 2px;
}

.detail-photo {
  display: block;
  max-height: 440px;
  border-radius: 8px;
}

.item-row {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.item-row:first-child {
  border-top: 0;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px;
}

.photo-card {
  text-decoration: none;
}

.photo-card img {
  display: block;
  aspect-ratio: 4 / 3;
}

.photo-card div {
  padding: 10px;
}

.empty-state {
  padding: 22px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
}

.update-form {
  display: grid;
  gap: 16px;
  max-width: 760px;
}

.camera-panel {
  display: grid;
  gap: 16px;
  min-height: min(58vh, 560px);
  align-content: center;
}

.camera-button {
  min-height: 76px;
  width: 100%;
  border-radius: 8px;
  font-size: 1.35rem;
}

.camera-file {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-preview {
  display: none;
  width: 100%;
  max-height: 42vh;
  border-radius: 8px;
  background: var(--panel-soft);
  object-fit: cover;
}

.photo-preview.visible {
  display: block;
}

.field {
  position: relative;
  display: grid;
  gap: 6px;
}

.field label,
.check-row {
  color: var(--muted);
  font-weight: 700;
}

.text-input,
.file-input {
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

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

.status-box {
  margin-top: 16px;
}

.suggestion-list {
  display: none;
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.suggestion-list.visible {
  display: grid;
}

.suggestion-option {
  display: grid;
  gap: 2px;
  width: 100%;
  min-height: 52px;
  padding: 8px 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
}

.suggestion-option:last-child {
  border-bottom: 0;
}

.suggestion-option:hover,
.suggestion-option:focus {
  background: var(--panel-soft);
  color: var(--ink);
}

.suggestion-name {
  font-weight: 760;
}

.submit-row {
  display: none;
  gap: 10px;
}

.submit-row.visible {
  display: grid;
}

.print-page {
  display: grid;
  gap: 18px;
  color: #111;
}

.print-toolbar {
  display: flex;
  justify-content: flex-end;
}

.print-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 20px;
  align-items: start;
  border-bottom: 2px solid #111;
  padding-bottom: 14px;
}

.print-header h1 {
  font-size: 2.2rem;
  line-height: 1;
  margin-bottom: 8px;
}

.print-header p {
  margin-bottom: 0;
  font-size: 1rem;
}

.print-qr {
  display: grid;
  gap: 6px;
  justify-items: center;
  text-align: center;
  font-weight: 800;
}

.print-qr img {
  width: 132px;
  height: 132px;
}

.print-cubby-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.print-cubby {
  min-height: 136px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 8px;
  border: 1.5px solid #111;
  padding: 8px;
  break-inside: avoid;
}

.print-cubby-number {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  background: #111;
  color: #fff;
  border-radius: 999px;
  font-weight: 900;
}

.print-cubby h2 {
  margin: 0 0 2px;
  font-size: 0.95rem;
}

.print-cubby p {
  margin-bottom: 0;
  font-size: 0.78rem;
  line-height: 1.25;
}

.print-position {
  font-weight: 800;
}

.print-left-section {
  border: 1.5px solid #111;
  padding: 10px 12px;
  break-inside: avoid;
}

.print-left-section h2 {
  margin-bottom: 4px;
}

@media (max-width: 760px) {
  body {
    padding-bottom: calc(74px + env(safe-area-inset-bottom));
  }

  .topbar {
    align-items: center;
    min-height: 58px;
    padding: 12px 14px;
    backdrop-filter: none;
  }

  .brand {
    font-size: 1.15rem;
  }

  .nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(54px, 1fr);
    gap: 2px;
    overflow-x: auto;
    padding: 7px 5px calc(7px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -10px 24px rgba(22, 32, 27, 0.08);
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav a {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border-radius: 8px;
    font-size: 0.78rem;
    text-align: center;
  }

  .app {
    width: 100%;
    padding: 14px 12px 20px;
  }

  .hero {
    gap: 14px;
    padding: 10px 0 18px;
  }

  h1 {
    font-size: 1.9rem;
    line-height: 1.05;
  }

  .hero .subtle {
    font-size: 1rem;
  }

  .search-form,
  .result-card,
  .detail-layout {
    grid-template-columns: 1fr;
  }

  .search-form {
    gap: 8px;
    max-width: none;
  }

  .search-input {
    min-height: 58px;
    padding: 0 14px;
    font-size: 1.05rem;
  }

  .search-form button {
    min-height: 54px;
    width: 100%;
    font-size: 1.05rem;
  }

  .answer {
    margin-bottom: 10px;
    padding: 13px 14px;
    border-left-width: 5px;
    font-size: 0.96rem;
    line-height: 1.35;
    box-shadow: none;
  }

  .result-card,
  .location-card,
  .photo-card,
  .category-card,
  .detail-panel {
    border-radius: 8px;
    box-shadow: none;
  }

  .result-thumb {
    height: auto;
    aspect-ratio: 4 / 3;
    object-fit: cover;
  }

  .result-body {
    padding: 12px;
  }

  .result-title-row {
    align-items: flex-start;
  }

  .badge {
    padding: 3px 7px;
    font-size: 0.72rem;
  }

  .location-line,
  .meta-line {
    font-size: 0.95rem;
    overflow-wrap: anywhere;
  }

  .button,
  button {
    min-height: 48px;
  }

  .button {
    width: 100%;
  }

  .chip-row {
    margin: 8px 0 10px;
  }

  .chip {
    font-size: 0.8rem;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .location-card {
    grid-template-rows: 150px auto;
  }

  .cubby-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-layout {
    gap: 12px;
  }

  .detail-panel {
    border: 0;
    background: transparent;
    padding: 0;
  }

  .detail-actions,
  .editor-toolbar,
  .editor-group-head,
  .editor-item-head {
    align-items: stretch;
    flex-direction: column;
  }

  .field-grid {
    grid-template-columns: 1fr;
  }

  .photo-stack {
    order: -1;
  }

  .photo-actions {
    flex-direction: column;
    align-items: flex-start;
  }

  .detail-photo {
    max-height: none;
    aspect-ratio: 4 / 3;
  }

  .camera-panel {
    min-height: calc(100dvh - 150px);
    align-content: start;
    padding-top: 8px;
  }

  .camera-button {
    min-height: 72px;
    font-size: 1.2rem;
  }

  .photo-preview {
    max-height: 34vh;
  }

  .suggestion-list {
    max-height: 210px;
  }

  .print-toolbar {
    position: sticky;
    top: 70px;
    z-index: 10;
    justify-content: stretch;
  }

  .print-toolbar button {
    width: 100%;
  }

  .print-header {
    grid-template-columns: 1fr;
  }

  .print-cubby-grid {
    grid-template-columns: 1fr;
  }
}

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

  body {
    background: #fff;
  }

  .topbar,
  .print-toolbar {
    display: none !important;
  }

  .app {
    width: 100%;
    padding: 0;
  }

  .print-page {
    gap: 10px;
  }

  .print-header {
    grid-template-columns: minmax(0, 1fr) 118px;
    gap: 12px;
    padding-bottom: 8px;
  }

  .print-header h1 {
    font-size: 24pt;
  }

  .print-header p {
    font-size: 9.5pt;
  }

  .print-qr img {
    width: 102px;
    height: 102px;
  }

  .print-qr p {
    font-size: 9pt;
  }

  .print-cubby-grid {
    gap: 5px;
  }

  .print-cubby {
    min-height: 112px;
    grid-template-columns: 26px minmax(0, 1fr);
    gap: 5px;
    padding: 5px;
    box-shadow: none;
  }

  .print-cubby-number {
    width: 23px;
    height: 23px;
    font-size: 9pt;
  }

  .print-cubby h2 {
    font-size: 8.5pt;
  }

  .print-cubby p {
    font-size: 7.2pt;
  }

  .print-left-section {
    padding: 6px 8px;
  }

  .print-left-section h2 {
    font-size: 11pt;
  }

  .print-left-section p {
    font-size: 8.5pt;
    margin-bottom: 0;
  }
}

@media (max-width: 420px) {
  .app {
    width: 100%;
  }

  .search-input {
    min-height: 58px;
    font-size: 1.05rem;
  }

  .cubby-grid {
    grid-template-columns: 1fr;
  }
}
