:root {
  --ink: #172033;
  --muted: #667085;
  --surface: #ffffff;
  --background: #f3f5f8;
  --line: #d9dee7;
  --primary: #1f5eff;
  --primary-dark: #1747c8;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --success-soft: #ecfdf3;
  --warning-soft: #fff8e7;
  --shadow: 0 12px 30px rgba(20, 31, 52, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--background);
}

body {
  margin: 0;
  min-height: 100%;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--background);
}

a {
  color: var(--primary);
  text-decoration: none;
}

button,
input,
textarea,
select {
  font: inherit;
}

img {
  max-width: 100%;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #162235;
  color: white;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.header-inner {
  width: min(1200px, calc(100% - 32px));
  min-height: 66px;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
  font-size: 1.05rem;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 35px;
  height: 35px;
  border-radius: 10px;
  background: #f6b73c;
  color: #162235;
  font-size: 1.35rem;
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 18px;
}

.top-nav a,
.link-button {
  color: white;
  opacity: 0.9;
  font-weight: 650;
}

.top-nav form {
  margin: 0;
}

.link-button {
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.page-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 32px auto 70px;
}

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 24px;
}

.page-heading h1 {
  margin: 3px 0 6px;
  font-size: clamp(1.8rem, 4vw, 2.7rem);
  line-height: 1.1;
}

.page-heading p {
  margin: 0;
  color: var(--muted);
}

.heading-actions,
.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 11px;
  padding: 10px 16px;
  font-weight: 750;
  cursor: pointer;
  transition: 0.15s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  background: var(--primary);
  color: white;
}

.button.primary:hover {
  background: var(--primary-dark);
}

.button.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.button.ghost {
  background: transparent;
  color: var(--muted);
}

.button.danger {
  background: var(--danger);
  color: white;
}

.button.full,
.full {
  width: 100%;
}

.back-link {
  display: inline-block;
  margin-bottom: 8px;
  font-weight: 700;
}

.search-form {
  display: flex;
  gap: 10px;
  padding: 14px;
  margin-bottom: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.search-form input {
  min-width: 0;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

.summary-card {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-card strong {
  display: block;
  font-size: 2rem;
  line-height: 1;
}

.summary-card span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
}

.section-block {
  margin-top: 30px;
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.section-title-row h2,
.section-block > h2 {
  margin: 0 0 14px;
}

.section-title-row h2 {
  margin-bottom: 0;
}

.section-title-row span {
  color: var(--muted);
}

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

.bin-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow);
  transition: 0.16s ease;
}

.bin-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 18px 36px rgba(20, 31, 52, 0.13);
}

.bin-photo {
  height: 170px;
  overflow: hidden;
  background: #e9edf3;
}

.bin-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-content: center;
  gap: 5px;
  text-align: center;
  color: #77839a;
}

.photo-placeholder span {
  font-size: 2.2rem;
}

.bin-card-body {
  padding: 17px;
}

.bin-number {
  margin-bottom: 5px;
  color: var(--primary);
  font-weight: 850;
}

.bin-card h3 {
  margin: 0;
  font-size: 1.1rem;
}

.bin-card p {
  min-height: 38px;
  margin: 8px 0 14px;
  color: var(--muted);
  font-size: 0.91rem;
}

.bin-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

.result-list,
.item-list {
  display: grid;
  gap: 10px;
}

.result-row,
.item-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  color: var(--ink);
}

.result-row span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.side-column {
  position: sticky;
  top: 92px;
}

.info-panel,
.qr-panel,
.upload-panel,
.form-card,
.login-card,
.warning-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.info-panel {
  padding: 20px;
  margin-bottom: 24px;
}

.info-panel h2,
.info-panel p {
  margin-top: 0;
}

.info-panel p {
  margin-bottom: 0;
}

.qr-panel {
  padding: 20px;
  text-align: center;
}

.qr-panel h2 {
  margin-top: 0;
}

.qr-panel img {
  display: block;
  width: 220px;
  max-width: 100%;
  margin: 10px auto;
  image-rendering: pixelated;
}

.qr-panel p,
.qr-panel small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.qr-panel small {
  display: block;
  margin-top: 13px;
  font-size: 0.7rem;
}

.item-card {
  align-items: flex-start;
}

.item-main {
  min-width: 0;
  flex: 1;
}

.item-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.item-title-row h3 {
  margin: 0;
}

.quantity,
.category-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  font-weight: 750;
  white-space: nowrap;
}

.quantity {
  padding: 5px 9px;
  background: #eaf0ff;
  color: #1747c8;
}

.category-pill {
  padding: 4px 9px;
  margin-top: 8px;
  background: #eef2f6;
  color: #475467;
  font-size: 0.8rem;
}

.item-card p {
  color: #475467;
}

.item-card small {
  color: var(--muted);
}

.item-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: right;
}

.danger-link {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.photo-card {
  overflow: hidden;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
}

.photo-card img {
  width: 100%;
  height: 190px;
  display: block;
  object-fit: cover;
}

.photo-card figcaption,
.photo-card form {
  padding: 10px 12px;
}

.photo-card form {
  padding-top: 0;
}

.upload-panel {
  display: grid;
  gap: 10px;
  padding: 20px;
}

.upload-panel h3 {
  margin: 0 0 4px;
}

.form-card,
.login-card {
  width: min(690px, 100%);
  padding: clamp(22px, 5vw, 38px);
  margin: 30px auto;
}

.login-card {
  width: min(450px, 100%);
}

.form-card h1,
.login-card h1 {
  margin-top: 0;
}

.stacked-form p,
.stacked-form {
  display: grid;
  gap: 8px;
}

.stacked-form p {
  margin: 0 0 12px;
}

.stacked-form label,
.upload-panel label {
  font-weight: 750;
}

.stacked-form input,
.stacked-form textarea,
.stacked-form select,
.upload-panel input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  background: white;
  color: var(--ink);
}

.stacked-form textarea {
  resize: vertical;
}

.stacked-form .helptext {
  color: var(--muted);
  font-size: 0.82rem;
}

.stacked-form ul.errorlist {
  margin: 0;
  padding-left: 20px;
  color: var(--danger);
}

.form-actions {
  margin-top: 14px;
}

.warning-panel {
  padding: 16px;
  margin-bottom: 20px;
  background: var(--danger-soft);
  color: var(--danger);
}

.messages {
  display: grid;
  gap: 10px;
  margin-bottom: 20px;
}

.message {
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
}

.message.success {
  background: var(--success-soft);
}

.message.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.empty-state {
  padding: 30px;
  border: 1px dashed #b9c1cf;
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
}

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

.print-label {
  min-height: 260px;
  display: grid;
  grid-template-columns: 1fr 190px;
  align-items: center;
  gap: 20px;
  padding: 24px;
  border: 3px solid #111827;
  border-radius: 16px;
  background: white;
  break-inside: avoid;
}

.print-label img {
  width: 190px;
  image-rendering: pixelated;
}

.print-label strong {
  font-size: 2.1rem;
}

.print-label h2 {
  margin: 8px 0;
  font-size: 1.25rem;
}

.print-label p {
  color: #475467;
}

.print-label small {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.66rem;
  color: #667085;
}

@media (max-width: 980px) {
  .bin-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .bin-detail-layout {
    grid-template-columns: 1fr;
  }

  .side-column {
    position: static;
  }

  .qr-panel {
    max-width: 420px;
  }

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

@media (max-width: 720px) {
  .header-inner {
    width: min(100% - 22px, 1200px);
  }

  .top-nav a {
    display: none;
  }

  .page-shell {
    width: min(100% - 22px, 1200px);
    margin-top: 22px;
  }

  .page-heading {
    flex-direction: column;
  }

  .heading-actions {
    width: 100%;
  }

  .heading-actions .button {
    flex: 1;
  }

  .search-form {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .search-form .ghost {
    grid-column: 1 / -1;
  }

  .summary-grid {
    gap: 8px;
  }

  .summary-card {
    padding: 14px 10px;
    text-align: center;
  }

  .summary-card strong {
    font-size: 1.55rem;
  }

  .summary-card span {
    font-size: 0.78rem;
  }

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

  .bin-photo {
    height: 125px;
  }

  .bin-card-body {
    padding: 13px;
  }

  .bin-card p {
    min-height: 0;
  }

  .bin-stats {
    display: grid;
    gap: 3px;
  }

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

  .photo-card img {
    height: auto;
    max-height: 440px;
  }

  .item-card {
    display: block;
  }

  .item-actions {
    flex-direction: row;
    margin-top: 14px;
  }

  .print-label {
    grid-template-columns: 1fr 135px;
    min-height: 220px;
    padding: 18px;
  }

  .print-label img {
    width: 135px;
  }
}

@media (max-width: 430px) {
  .brand span:last-child {
    font-size: 0.95rem;
  }

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

  .bin-photo {
    height: 190px;
  }

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

  .search-form .button {
    width: 100%;
  }

  .summary-card span {
    min-height: 30px;
  }
}

@media print {
  @page {
    margin: 0.35in;
  }

  body {
    background: white;
  }

  .site-header,
  .no-print,
  .messages {
    display: none !important;
  }

  .page-shell {
    width: 100%;
    margin: 0;
  }

  .label-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.18in;
  }

  .print-label {
    min-height: 3.2in;
    box-shadow: none;
  }
}

/* Single mobile and desktop photo control */
.photo-upload-help {
  margin: 0 0 4px;
  color: var(--muted);
}

.single-photo-source {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  border: 2px solid var(--primary);
  border-radius: 14px;
  background: #eef3ff;
}

.single-photo-source label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
}

.single-photo-source strong {
  color: var(--primary-dark);
  font-size: 1.1rem;
}

.single-photo-source span {
  color: var(--muted);
  font-size: 0.88rem;
}

.single-photo-source input[type="file"] {
  display: block;
  width: 100%;
  min-height: 50px;
  margin: 0;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
  color: var(--text);
  font: inherit;
}

.single-photo-source input[type="file"]::file-selector-button {
  min-height: 36px;
  margin-right: 10px;
  padding: 7px 14px;
  border: 0;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.photo-selection-status {
  padding: 11px 13px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  color: var(--muted);
  background: #f8fafc;
  overflow-wrap: anywhere;
}

.photo-selection-status.ready {
  border-style: solid;
  background: var(--success-soft);
  color: #067647;
  font-weight: 700;
}

#save-photo-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
}


/* Compact dashboard and bin contents */
.compact-bin-list {
  gap: 8px;
}

.compact-bin-row {
  min-height: 68px;
  padding-top: 12px;
  padding-bottom: 12px;
}

.compact-bin-row strong {
  font-size: 1.05rem;
}

.compact-item-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.compact-item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: white;
}

.compact-item-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.compact-item-main strong {
  font-size: 1rem;
}

.compact-item-main span {
  color: var(--muted);
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.compact-item-quantity {
  padding: 5px 9px;
  border-radius: 999px;
  background: #eef3ff;
  color: var(--primary-dark);
  font-weight: 700;
  white-space: nowrap;
}

.compact-item-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}

@media (max-width: 640px) {
  .compact-item-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 9px 12px;
  }

  .compact-item-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }
}

/* Installed-app safe areas for notched phones and the Home indicator. */
@supports (padding: env(safe-area-inset-top)) {
  .site-header {
    padding-top: env(safe-area-inset-top);
    padding-right: env(safe-area-inset-right);
    padding-left: env(safe-area-inset-left);
  }

  .page-shell {
    width: min(
      1200px,
      calc(
        100% - 32px - env(safe-area-inset-left) -
        env(safe-area-inset-right)
      )
    );
    margin-bottom: calc(70px + env(safe-area-inset-bottom));
  }
}
