:root {
  --green: #3f6b3a;
  --green-dark: #2c4d29;
  --green-light: #6a9c5f;
  --cream: #faf7f0;
  --sand: #f1ead9;
  --earth: #8b6f47;
  --text: #2a2a26;
  --muted: #76736a;
  --border: #e3ddcd;
  --danger: #c0392b;
  --shadow: 0 2px 10px rgba(60, 50, 30, 0.08);
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must win over rules like `.modal { display: flex }`,
   otherwise toggling `el.hidden = true` won't actually hide the element. */
[hidden] {
  display: none !important;
}

body {
  font-family: "Segoe UI", system-ui, sans-serif;
  margin: 0;
  background: var(--cream);
  color: var(--text);
  line-height: 1.5;
}

h1, h2, h3 {
  font-family: Georgia, "Times New Roman", serif;
}

a {
  color: var(--green-dark);
}

/* --- Header --- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: var(--green-dark);
  color: var(--cream);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  font-size: 2rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.5rem;
}

.tagline {
  margin: 0;
  font-size: 0.85rem;
  opacity: 0.85;
}

.cart-toggle {
  background: var(--green-light);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.cart-toggle:hover {
  background: var(--green);
}

.cart-count {
  background: #fff;
  color: var(--green-dark);
  border-radius: 999px;
  min-width: 1.5rem;
  text-align: center;
  font-size: 0.8rem;
  padding: 0.1rem 0.4rem;
}

/* --- Store --- */
.store {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.intro {
  background: var(--sand);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 2rem;
}

.intro p {
  margin: 0;
}

.category {
  margin-bottom: 2.5rem;
}

.category h2 {
  border-bottom: 2px solid var(--border);
  padding-bottom: 0.5rem;
  color: var(--green-dark);
}

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

.product-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}

.product-card h3 {
  margin: 0 0 0.35rem;
}

.product-desc {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 0.75rem;
  flex: 1;
}

.product-price {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--green-dark);
  margin: 0 0 0.75rem;
}

.product-price .unit {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--muted);
}

/* --- Quantity controls --- */
.qty-controls {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--sand);
  border-radius: 999px;
  padding: 0.25rem;
}

.qty-btn {
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.qty-btn:hover {
  background: var(--green-dark);
}

.qty-value {
  min-width: 1.5rem;
  text-align: center;
  font-weight: 600;
}

/* --- Cart drawer --- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 30;
}

.cart-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 100%);
  height: 100%;
  background: var(--cream);
  z-index: 40;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.cart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.cart-header h2 {
  margin: 0;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--muted);
}

.cart-items {
  flex: 1;
}

.cart-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.cart-row-info {
  display: flex;
  flex-direction: column;
}

.cart-row-total {
  font-weight: 700;
  min-width: 4rem;
  text-align: right;
}

.cart-total {
  display: flex;
  justify-content: space-between;
  font-size: 1.25rem;
  padding: 1rem 0;
  border-top: 2px solid var(--border);
  margin-top: 0.5rem;
}

/* --- Checkout form --- */
.checkout h3 {
  margin: 0.5rem 0;
}

label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

input, textarea, select {
  width: 100%;
  font-size: 1rem;
  padding: 0.55rem;
  margin-top: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
  font-weight: 400;
}

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--green-light);
  border-color: var(--green-light);
}

.fulfillment {
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 0 0 0.75rem;
}

.fulfillment legend {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0 0.4rem;
}

label.radio, label.checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
}

label.radio input, label.checkbox input {
  width: auto;
  margin: 0;
}

.primary-btn {
  width: 100%;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

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

.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.ghost-btn {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.ghost-btn:hover {
  background: var(--sand);
}

.ghost-btn.danger {
  color: var(--danger);
  border-color: #e6c4be;
}

/* --- Confirmation --- */
.confirmation {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
}

.confirmation-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 380px;
  text-align: center;
}

.confirmation-mark {
  font-size: 3rem;
}

.confirmation-card h2 {
  margin: 0.5rem 0;
}

/* --- Footer --- */
.site-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

/* --- Shared utility --- */
.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.error {
  color: var(--danger);
  min-height: 1.2em;
  margin: 0.5rem 0;
}

.loading {
  color: var(--muted);
  padding: 2rem 0;
  text-align: center;
}

/* --- Admin --- */
.admin {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.login-card, .modal-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  max-width: 380px;
  margin: 2rem auto;
}

.login-card h2 {
  margin-top: 0;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid var(--border);
  margin-bottom: 1.5rem;
}

.tab {
  background: none;
  border: none;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}

.tab.active {
  color: var(--green-dark);
  border-bottom-color: var(--green);
  font-weight: 600;
}

.tab.logout {
  margin-left: auto;
  color: var(--danger);
}

.badge {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 0.75rem;
  padding: 0.05rem 0.45rem;
}

.badge:empty {
  display: none;
}

/* Orders */
.order-card {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 5px solid var(--muted);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.order-card.status-new { border-left-color: var(--green); }
.order-card.status-confirmed { border-left-color: #2980b9; }
.order-card.status-ready { border-left-color: #e67e22; }
.order-card.status-completed { border-left-color: var(--muted); opacity: 0.75; }
.order-card.status-cancelled { border-left-color: var(--danger); opacity: 0.6; }

.order-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.status-select {
  width: auto;
  margin: 0;
}

.order-meta {
  margin: 0.5rem 0;
  font-size: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.pay-pill {
  display: inline-block;
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.pay-pill.paid {
  background: #e3f3e0;
  color: var(--green-dark);
}

.pay-pill.unpaid {
  background: #fdeccd;
  color: #9a6700;
}

.pay-pill.onpickup {
  background: var(--sand);
  color: var(--earth);
}

.order-items {
  margin: 0.5rem 0;
  padding-left: 1.2rem;
}

.order-notes {
  background: var(--sand);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.order-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  margin-top: 0.5rem;
  font-size: 1.1rem;
}

/* Products admin */
.products-admin {
  margin-top: 1rem;
}

.product-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  margin-bottom: 0.6rem;
}

.product-row.unavailable {
  opacity: 0.65;
}

.product-row-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.product-row-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.pill {
  display: inline-block;
  background: var(--sand);
  border-radius: 999px;
  padding: 0.05rem 0.5rem;
  font-size: 0.75rem;
  color: var(--earth);
  width: fit-content;
}

#new-product-btn {
  width: auto;
  padding: 0.6rem 1.1rem;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
  overflow-y: auto;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  margin: auto;
}

.modal-card h2 {
  margin-top: 0;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row label {
  flex: 1;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.modal-actions .ghost-btn,
.modal-actions .primary-btn {
  width: auto;
}

@media (max-width: 480px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .brand h1 {
    font-size: 1.2rem;
  }
}
