/* =========================================
   DESIGN TOKENS
   ========================================= */
:root {
  --green-deep:    #1a4a2e;
  --green-mid:     #2d7a4f;
  --green-light:   #4caf7d;
  --green-pale:    #e8f5ee;
  --orange:        #e8682a;
  --orange-light:  #fdf0e8;
  --sand:          #f7f4ef;
  --white:         #ffffff;
  --gray-100:      #f4f5f7;
  --gray-200:      #e8eaed;
  --gray-400:      #9aa0ab;
  --gray-700:      #3d4350;
  --gray-900:      #1c1f26;
  --radius-sm:     6px;
  --radius-md:     10px;
  --radius-lg:     16px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:     0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg:     0 12px 40px rgba(0,0,0,0.16);
  --topbar-h:      56px;
  --bottombar-h:   52px;
  --sidebar-w:     220px;
  --font-head:     'Sora', sans-serif;
  --font-body:     'DM Sans', sans-serif;
}

/* =========================================
   RESET & BASE
   ========================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--sand);
  color: var(--gray-900);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

button { font-family: var(--font-body); cursor: pointer; border: none; }
input, textarea, select { font-family: var(--font-body); }
a { color: var(--green-mid); text-decoration: none; }
a:hover { text-decoration: underline; }

/* =========================================
   LAYOUT
   ========================================= */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: calc(100vh - var(--topbar-h) - var(--bottombar-h));
  overflow: hidden;
}

.scroll-y { overflow-y: auto; }

/* =========================================
   TOP BAR
   ========================================= */
.app-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-logo {
  height: 30px;
  width: 30px;
  object-fit: contain;
  border-radius: 6px;
}

.app-title {
  font-family: var(--font-head);
  font-size: 17px;
  font-weight: 700;
  color: var(--green-deep);
}

.history-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--green-pale);
  color: var(--green-deep);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  transition: background 0.2s;
}

.history-btn:hover { background: #d1ecdb; }

/* =========================================
   SIDEBAR
   ========================================= */
.sidebar {
  background: var(--white);
  border-right: 1px solid var(--gray-200);
  padding: 14px 10px;
}

.sidebar-title {
  font-family: var(--font-head);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gray-400);
  padding: 0 8px 10px;
}

.sidebar ul {
  list-style: none;
}

.sidebar li {
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 2px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--gray-700);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar li:hover { background: var(--green-pale); color: var(--green-deep); }
.sidebar li.active {
  background: var(--green-pale);
  color: var(--green-deep);
  font-weight: 700;
  border-left: 3px solid var(--green-mid);
  padding-left: 7px;
}

/* =========================================
   MAIN CONTENT
   ========================================= */
.main {
  flex: 1;
  padding: 16px;
  background: var(--sand);
}

/* Search bar */
.top-bar2 {
  margin-bottom: 16px;
}

.search-wrap {
  position: relative;
  max-width: 380px;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gray-400);
  pointer-events: none;
}

#productSearch {
  width: 100%;
  padding: 9px 12px 9px 36px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  background: var(--white);
  transition: border-color 0.2s, box-shadow 0.2s;
}

#productSearch:focus {
  outline: none;
  border-color: var(--green-light);
  box-shadow: 0 0 0 3px rgba(76,175,125,0.15);
}

/* =========================================
   PRODUCT GRID
   ========================================= */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.product-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.product-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.product-image {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
  background: var(--gray-100);
}

.product-details {
  padding: 12px;
}

.product-name {
  font-family: var(--font-head);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--gray-900);
}

.product-price {
  font-size: 13px;
  color: var(--gray-700);
  margin-bottom: 4px;
}

.product-stock {
  font-size: 12px;
  color: var(--gray-400);
  margin-bottom: 10px;
}

.fpo-badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  margin-bottom: 10px;
}
.fpo-badge.active { background: #e6f4ea; color: #2d7a4f; }
.fpo-badge.inactive { background: #fdecea; color: #c62828; }

.add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 8px;
  background: var(--orange);
  color: white;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
}

.add-btn:hover:not(.disabled) { background: #d4551e; }

.add-btn.disabled {
  background: var(--gray-200);
  color: var(--gray-400);
  cursor: not-allowed;
  pointer-events: none;
}

/* Qty controls */
.qty-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  border: 1.5px solid var(--green-light);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.qty-box button {
  width: 32px;
  height: 32px;
  background: var(--green-pale);
  color: var(--green-deep);
  font-size: 18px;
  font-weight: 700;
  transition: background 0.15s;
  border: none;
}

.qty-box button:hover { background: #c8e6d4; }

.qty-value {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  color: var(--green-deep);
  padding: 0 4px;
}

/* =========================================
   FLOATING CART
   ========================================= */
#cartFloat {
  position: fixed;
  bottom: calc(var(--bottombar-h) + 14px);
  right: 20px;
  background: var(--orange);
  color: white;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(232,104,42,0.45);
  z-index: 500;
  transition: transform 0.2s;
}

#cartFloat:hover { transform: scale(1.07); }

#cartBadge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--green-deep);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 12px;
  min-width: 20px;
  text-align: center;
  line-height: 1.4;
}

/* =========================================
   OVERLAY & MODAL
   ========================================= */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 900;
  backdrop-filter: blur(2px);
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--white);
  width: 680px;
  max-width: 96vw;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: var(--radius-lg);
  z-index: 1000;
  padding: 0;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px 14px;
  position: sticky;
  top: 0;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  z-index: 10;
}

.modal-title {
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 700;
  color: var(--gray-900);
}

.modal-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--gray-100);
  color: var(--gray-700);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.modal-close-btn:hover { background: var(--gray-200); }

/* Scrollbar styling inside modal */
.modal::-webkit-scrollbar { width: 5px; }
.modal::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 4px; }

/* =========================================
   MODAL SECTIONS
   ========================================= */
.section {
  padding: 18px 24px;
}

.section-title {
  font-family: var(--font-head);
  font-size: 13.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray-400);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.section-divider {
  height: 1px;
  background: var(--gray-100);
  margin: 0 24px;
}

/* FPO Info card */
.info-card {
  margin: 0 24px;
  background: var(--green-pale);
  border: 1px solid #c5e4d0;
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-top: 14px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 13.5px;
}

.info-label { color: var(--gray-400); font-weight: 500; }
.info-value { color: var(--gray-900); font-weight: 600; text-align: right; max-width: 65%; }

/* Table */
.table-wrap { overflow-x: auto; }

.product-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.product-table th {
  background: var(--gray-100);
  padding: 9px 10px;
  text-align: left;
  font-weight: 600;
  color: var(--gray-700);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.product-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-900);
}

/* Billing card */
.billing-card {
  background: var(--gray-100);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  font-size: 14px;
}

.billing-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  color: var(--gray-700);
}

.billing-row.total-row {
  border-top: 1px solid var(--gray-200);
  margin-top: 6px;
  padding-top: 10px;
  font-size: 15px;
  color: var(--gray-900);
  font-weight: 700;
}

/* Delivery estimate */
.pincode-tag {
  font-size: 12px;
  font-weight: 600;
  background: var(--orange-light);
  color: var(--orange);
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: none;
  letter-spacing: 0;
}

.change-pin-btn {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--green-mid);
  background: none;
  text-decoration: underline;
  text-underline-offset: 2px;
  padding: 0;
  text-transform: none;
  letter-spacing: 0;
}

.estimate-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.estimate-item {
  background: var(--gray-100);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
}

.estimate-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gray-400);
  font-weight: 600;
  margin-bottom: 4px;
}

.estimate-val {
  display: block;
  font-size: 15px;
  font-weight: 700;
  font-family: var(--font-head);
  color: var(--green-deep);
}

/* Form fields */
.field {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
  margin-bottom: 5px;
}

.field input,
.field textarea {
  padding: 8px 11px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--white);
  color: var(--gray-900);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field input:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--green-light);
  box-shadow: 0 0 0 3px rgba(76,175,125,0.12);
}

.field textarea { resize: vertical; min-height: 64px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

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

.field-sm { max-width: 180px; }

/* Detect button */
.detect-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.detect-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  background: var(--green-pale);
  color: var(--green-deep);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  transition: background 0.2s;
}

.detect-btn:hover { background: #c8e6d4; }

.loc-status {
  font-size: 12px;
  color: var(--gray-400);
}

/* Payment */
.payment-options {
  display: flex;
  gap: 12px;
}

.payment-option { cursor: pointer; }
.payment-option input { display: none; }

.payment-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 500;
  transition: border-color 0.2s, background 0.2s;
  cursor: pointer;
}

.payment-option input:checked + .payment-box {
  border-color: var(--green-mid);
  background: var(--green-pale);
  color: var(--green-deep);
  font-weight: 600;
}

.payment-icon { font-size: 18px; }

/* Submit */
.submit-section {
  display: flex;
  align-items: center;
  gap: 14px;
}

.submit-btn {
  flex: 1;
  padding: 13px;
  background: var(--green-mid);
  color: white;
  border-radius: var(--radius-md);
  font-family: var(--font-head);
  font-size: 15px;
  font-weight: 700;
  transition: background 0.2s, transform 0.1s;
  letter-spacing: 0.02em;
}

.submit-btn:hover { background: var(--green-deep); }
.submit-btn:active { transform: scale(0.99); }

#loadingWrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--gray-400);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2.5px solid var(--gray-200);
  border-top-color: var(--green-mid);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Legal note */
.legal-note {
  font-size: 12.5px;
  color: var(--gray-400);
  line-height: 1.7;
  padding: 0 24px 24px;
}

.legal-note a { color: var(--green-mid); }

/* =========================================
   DISCARD CONFIRM DIALOG
   ========================================= */
.confirm {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  backdrop-filter: blur(2px);
}

.confirm-box {
  background: white;
  padding: 28px 28px 24px;
  border-radius: var(--radius-lg);
  text-align: center;
  width: 320px;
  box-shadow: var(--shadow-lg);
}

.confirm-icon {
  font-size: 32px;
  margin-bottom: 12px;
}

.confirm-box p {
  font-size: 14.5px;
  color: var(--gray-700);
  line-height: 1.6;
  margin-bottom: 20px;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.confirm-cancel {
  padding: 9px 20px;
  background: var(--gray-100);
  color: var(--gray-700);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.2s;
}
.confirm-cancel:hover { background: var(--gray-200); }

.confirm-ok {
  padding: 9px 20px;
  background: var(--orange);
  color: white;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.2s;
}
.confirm-ok:hover { background: #d4551e; }

/* =========================================
   PINCODE POPUP
   ========================================= */
.pincode-popup {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
  backdrop-filter: blur(4px);
}

.pincode-popup-content {
  background: white;
  padding: 32px 28px;
  border-radius: var(--radius-lg);
  text-align: center;
  width: 320px;
  box-shadow: var(--shadow-lg);
}

.pincode-icon { font-size: 36px; margin-bottom: 10px; }

.pincode-popup-content h3 {
  font-family: var(--font-head);
  font-size: 18px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 6px;
}

.pincode-sub {
  font-size: 13px;
  color: var(--gray-400);
  margin-bottom: 18px;
}

.pincode-popup-content input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: var(--font-head);
  letter-spacing: 0.08em;
  text-align: center;
  margin-bottom: 14px;
}

.pincode-popup-content input:focus {
  outline: none;
  border-color: var(--green-light);
  box-shadow: 0 0 0 3px rgba(76,175,125,0.15);
}

.pincode-popup-content button {
  width: 100%;
  padding: 11px;
  background: var(--green-mid);
  color: white;
  border-radius: var(--radius-sm);
  font-family: var(--font-head);
  font-size: 15px;
  font-weight: 700;
  transition: background 0.2s;
}

.pincode-popup-content button:hover { background: var(--green-deep); }

/* =========================================
   BOTTOM BAR
   ========================================= */
.app-bottombar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottombar-h);
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  z-index: 200;
  padding: 0 12px;
}

.row-1 {
  display: flex;
  gap: 20px;
}

.row-1 a {
  font-size: 12px;
  color: var(--orange);
  font-weight: 500;
}

.row-1 a:hover { color: var(--green-mid); text-decoration: none; }

.row-2 {
  font-size: 11px;
  color: var(--gray-400);
}

/* =========================================
   HIDDEN UTILITY
   ========================================= */
.hidden { display: none !important; }

/* =========================================
   RESPONSIVE — TABLET
   ========================================= */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 140px;
  }

  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
    gap: 10px;
  }

  .product-image { height: 120px; }

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

/* =========================================
   RESPONSIVE — MOBILE
   ========================================= */
@media (max-width: 600px) {
  :root {
    --topbar-h: 50px;
    --bottombar-h: 64px;
  }

  .layout {
    grid-template-columns: 110px 1fr;
    height: calc(100vh - var(--topbar-h) - var(--bottombar-h));
  }

  .hide1 { display: none; }

  .sidebar {
    padding: 8px 6px;
  }

  .sidebar li {
    font-size: 12px;
    padding: 8px 6px;
  }

  .main { padding: 10px; }

  .app-title { font-size: 14px; }

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

  .product-image { height: 110px; }

  .product-name { font-size: 12.5px; }

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

  .field-sm { max-width: 100%; }

  .payment-options { flex-direction: column; }

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

  .row-1 { gap: 10px; flex-wrap: wrap; justify-content: center; }
  .row-1 a { font-size: 11px; }
  .row-2 { font-size: 10px; text-align: center; }

  .app-bottombar { height: 64px; padding: 4px 8px; }

  .modal { border-radius: var(--radius-md); }
  .info-card { margin: 0 14px; margin-top: 12px; }
  .section { padding: 14px 16px; }
  .section-divider { margin: 0 16px; }
  .legal-note { padding: 0 16px 20px; }
  .modal-header { padding: 14px 16px 12px; }
}

@media (max-width: 380px) {
  .product-grid {
    grid-template-columns: 1fr;
  }
}
