/* ============================================
   Winco Staples — Styles
   Green / White — Clean & Functional
   ============================================ */

:root {
  --green:       #1a5c2a;
  --green-dark:  #0f3d1a;
  --green-light: #2a8c42;
  --green-pale:  #e8f5eb;
  --gold:        #c4952a;
  --gold-light:  #f5c842;
  --white:       #ffffff;
  --cream:       #f8f8f6;
  --gray-light:  #f0f0ee;
  --gray:        #d8d8d4;
  --gray-mid:    #999990;
  --text-dark:   #1a1a18;
  --text-mid:    #4a4a45;
  --text-light:  #888880;
  --red:         #dc2626;
  --red-light:   #fee2e2;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.10);
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;
  --header-h:   56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--cream);
  color: var(--text-dark);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ============ SCREENS ============ */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--cream);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
.screen.active { transform: translateX(0); }
.screen.slide-out { transform: translateX(-28%); }

/* ============ HEADER ============ */
.app-header {
  background: var(--green);
  color: var(--white);
  height: var(--header-h);
  flex-shrink: 0;
  padding: 0 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.app-icon { font-size: 22px; flex-shrink: 0; }

.app-header h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--white);
  white-space: nowrap;
}

.last-updated {
  font-size: 10px;
  color: rgba(255,255,255,0.55);
}

.header-actions { display: flex; gap: 4px; }

.icon-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: var(--white);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.2s;
}
.icon-btn:active { background: rgba(255,255,255,0.28); }

.save-btn {
  background: var(--gold);
  color: var(--white);
  border: none;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.delete-btn {
  background: var(--red-light);
  color: var(--red);
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  margin-right: 4px;
}

.delete-btn.hidden { display: none; }

/* ============ MODE TABS ============ */
.mode-tabs {
  display: flex;
  background: var(--green-dark);
  flex-shrink: 0;
}

.mode-tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.mode-tab.active {
  color: var(--white);
  border-bottom-color: var(--gold);
}

/* ============ SHOPPING BAR ============ */
.shopping-bar {
  background: var(--green-pale);
  border-bottom: 1px solid var(--green-light);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--green-dark);
}

.shopping-bar.hidden { display: none; }

.clear-checks-btn {
  background: none;
  border: 1px solid var(--green-light);
  color: var(--green);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* ============ ITEM LIST ============ */
.item-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 10px;
  padding-bottom: calc(16px + var(--safe-bottom));
}

/* ---- Inventory Item ---- */
.inv-item {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  margin-bottom: 5px;
  box-shadow: var(--shadow-sm);
}

.inv-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.inv-item-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dark);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inv-item-badges {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  align-items: center;
}

.inv-badge-par {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-mid);
  background: var(--gray-light);
  padding: 2px 6px;
  border-radius: 100px;
  white-space: nowrap;
}

.inv-badge-need {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 100px;
  white-space: nowrap;
}

.inv-badge-need.need {
  background: #fef3c7;
  color: #b45309;
}

.inv-badge-need.ok {
  background: var(--green-pale);
  color: var(--green);
}

.inv-item-bottom {
  display: flex;
  align-items: center;
  gap: 6px;
}

.inv-meta {
  font-size: 12px;
  color: var(--text-light);
  white-space: nowrap;
  flex-shrink: 0;
}

.edit-item-btn {
  background: none;
  border: none;
  color: var(--gray-mid);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  padding: 0;
}

.qty-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-shrink: 0;
}

.qty-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: var(--green-pale);
  color: var(--green);
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
  line-height: 1;
  flex-shrink: 0;
}
.qty-btn:active { background: var(--green); color: var(--white); }

.qty-display {
  width: 44px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-dark);
  cursor: pointer;
  padding: 2px 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--gray);
  background: var(--gray-light);
  -moz-appearance: textfield;
}
.qty-display::-webkit-outer-spin-button,
.qty-display::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.qty-display:focus {
  outline: none;
  border-color: var(--green);
  background: var(--white);
}

.qty-to-buy {
  min-width: 30px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 5px;
  border-radius: 100px;
  flex-shrink: 0;
}

.qty-to-buy.need {
  background: #fef3c7;
  color: #b45309;
}

.qty-to-buy.ok {
  background: var(--green-pale);
  color: var(--green);
}

/* ---- Shopping Item ---- */
.shop-item {
  background: var(--white);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s;
}

.shop-item.checked {
  opacity: 0.5;
}

.shop-check {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--gray);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s;
  background: var(--white);
}

.shop-item.checked .shop-check {
  background: var(--green);
  border-color: var(--green);
}

.shop-item.checked .shop-check::after {
  content: '';
  width: 6px;
  height: 10px;
  border: 2px solid var(--white);
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translate(-1px, -1px);
  display: block;
}

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

.shop-item-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dark);
}

.shop-item.checked .shop-item-name {
  text-decoration: line-through;
  color: var(--text-light);
}

.shop-item-price {
  font-size: 12px;
  color: var(--text-light);
  margin-top: 2px;
}

.shop-qty-badge {
  background: var(--gold);
  color: var(--white);
  font-size: 14px;
  font-weight: 700;
  min-width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0 6px;
}

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
  font-size: 14px;
  line-height: 1.6;
}

/* ============ LOADING ============ */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(248,248,246,0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 50;
  font-size: 14px;
  color: var(--text-mid);
}
.loading-overlay.hidden { display: none; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ EDIT FORM ============ */
.edit-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px;
  padding-bottom: calc(24px + var(--safe-bottom));
}

.form-section { margin-bottom: 20px; }

.form-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--green);
  border-bottom: 2px solid var(--green);
  padding-bottom: 4px;
  margin-bottom: 12px;
}

.form-row { margin-bottom: 12px; }

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mid);
  margin-bottom: 4px;
}

.form-input {
  width: 100%;
  background: var(--white);
  border: 1.5px solid var(--gray);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  color: var(--text-dark);
  font-family: inherit;
  transition: border-color 0.2s;
}
.form-input:focus { outline: none; border-color: var(--green); }

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

/* ============ PIN MODAL ============ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}

.modal-box {
  position: relative;
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  width: 300px;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.modal-box h2 { font-size: 18px; font-weight: 700; color: var(--green); margin-bottom: 4px; }
.modal-box p  { font-size: 13px; color: var(--text-light); margin-bottom: 20px; }

.pin-dots { display: flex; justify-content: center; gap: 12px; margin-bottom: 8px; }

.pin-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid var(--gray);
  transition: background 0.15s, border-color 0.15s;
}
.pin-dot.filled { background: var(--green); border-color: var(--green); }

.pin-error { font-size: 12px; color: var(--red); height: 16px; margin-bottom: 8px; }
.pin-error.hidden { visibility: hidden; }

.pin-keypad { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; margin-top: 12px; }

.pin-key {
  background: var(--gray-light);
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.pin-key:active { background: var(--gray); }
.pin-cancel { background: #fee2e2; color: var(--red); }

/* ============ UPDATE BANNER ============ */
.update-banner {
  position: fixed;
  bottom: calc(12px + var(--safe-bottom));
  left: 12px; right: 12px;
  background: var(--green-dark);
  color: var(--white);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-md);
  z-index: 300;
}
.update-banner.hidden { display: none; }
.update-banner span { flex: 1; font-size: 13px; font-weight: 600; }

#btn-update {
  background: var(--gold);
  color: var(--white);
  border: none;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.dismiss-update {
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  font-size: 12px;
  cursor: pointer;
}

::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray); border-radius: 2px; }
