/* Ensure hidden elements never render until JS shows them */
[hidden] {
  display: none !important;
}

:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #d7deea;
  --primary: #1d4ed8;
  --success: #15803d;
  --danger: #b91c1c;
  --secondary: #4338ca;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px;
  background: #0f172a;
  color: #fff;
}

.app-header h1 { margin: 0 0 6px; }
.subtitle { margin: 0; color: #cbd5e1; }
.header-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}
.stack-form {
  display: grid;
  gap: 12px;
}
label {
  display: grid;
  gap: 6px;
  font-weight: 600;
}
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
}
.full-width { grid-column: 1 / -1; }
.divider {
  text-align: center;
  color: var(--muted);
  font-weight: 700;
  padding: 4px 0;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 700;
  background: #e5e7eb;
  color: #111827;
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-small { padding: 10px 12px; font-size: 13px; }
.full-width-btn { width: 100%; }

.section-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}
.summary-pill {
  background: #eef2ff;
  color: #312e81;
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 700;
}

.receipt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 16px;
}
.receipt-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}
.receipt-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.receipt-title { margin: 0 0 4px; font-size: 24px; }
.receipt-meta { margin: 0; color: var(--muted); }
.editable-qty-wrap {
  margin: 16px 0 12px;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(140px, 1fr);
  gap: 12px;
  align-items: stretch;
}
.inline-label {
  display: grid;
  gap: 6px;
}
.next-pallet-input {
  font-size: 22px;
  font-weight: 800;
  text-align: center;
}

.next-pallet-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}
.reset-qty-btn {
  min-width: 90px;
  height: 100%;
}
.helper-text {
  margin: 8px 0 0;
  color: #334155;
  font-size: 14px;
}
.big-btn {
  min-height: 70px;
  border: 0;
  border-radius: 16px;
  font-size: 24px;
  font-weight: 800;
  cursor: pointer;
}
.plus-btn {
  background: #dcfce7;
  color: #166534;
}
.line-footer {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.breakdown-text {
  display: grid;
  gap: 6px;
}
.breakdown-label {
  font-weight: 700;
  color: var(--text);
}
.pallet-breakdown-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pallet-chip {
  border: 1px solid #fecaca;
  background: #fff1f2;
  color: #9f1239;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.pallet-chip:hover {
  filter: brightness(0.98);
}
.breakdown-empty {
  color: var(--muted);
}
.empty-state {
  display: none;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 18px;
}
.catalog-grid, .history-list {
  display: grid;
  gap: 12px;
}
.catalog-card, .history-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #fafcff;
}
.catalog-card h3, .history-card h3 { margin: 0 0 8px; }
.catalog-card p, .history-card p { margin: 4px 0; }
.history-line-items {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
  color: var(--muted);
}

@media (max-width: 850px) {
  .two-col, .form-grid, 
  .app-header {
    flex-direction: column;
  }
}

.qty-panel {
  padding: 12px;
  border-radius: 14px;
  background: #eef6ff;
  border: 1px solid #cfe1ff;
  min-width: 0;
}
.add-pallet-btn {
  width: 100%;
  height: 100%;
  min-height: 96px;
}
@media (max-width: 700px) {
  .editable-qty-wrap {
    grid-template-columns: 1fr;
  }
  .add-pallet-btn {
    min-height: 56px;
  }
}


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

.nav-link {
  text-decoration: none;
  padding: 10px 14px;
  border-radius: 12px;
  background: #e9eef7;
  color: #1d2a44;
  font-weight: 700;
}

.nav-link.active {
  background: #1d4ed8;
  color: #fff;
}

.single-page {
  grid-template-columns: 1fr;
}

.product-list,
.history-list,
.receipt-items {
  display: grid;
  gap: 14px;
}

.product-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid #d9e1ef;
  border-radius: 16px;
  background: #fff;
}

.product-row h3 {
  margin: 0 0 4px;
}

.product-row p {
  margin: 0;
}

.product-row-main {
  min-width: 0;
}

.compact-meta {
  grid-template-columns: repeat(1, minmax(0, 180px));
}

.panel-head-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.history-card-head,
.receipt-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pallet-breakdown-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}

@media (max-width: 700px) {
  .top-nav,
  .panel-head-actions,
  .product-row,
  .history-card-head,
  .receipt-card-head {
    flex-direction: column;
    align-items: stretch;
  }
}


.receive-form-grid {
  align-items: start;
}

.product-search-label {
  position: relative;
}

.product-search-wrap {
  position: relative;
}

.product-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid #d9e1ef;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 12px 24px rgba(16, 24, 40, 0.12);
  max-height: 260px;
  overflow-y: auto;
}

.product-search-option {
  width: 100%;
  border: 1px solid #dbe4f0;
  background: #f8fbff;
  border-radius: 12px;
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
  display: grid;
  gap: 2px;
}

.product-search-option:hover,
.product-search-option:focus {
  background: #eef6ff;
  border-color: #b9d3ff;
}

.product-search-name {
  font-weight: 700;
  color: #14213d;
}

.product-search-qty {
  font-size: 0.9rem;
  color: #5b6475;
}

.receive-form-grid-simple {
  grid-template-columns: 1fr;
  align-items: start;
}
.product-search-wrap{position:relative;}
