/* =============================================================
   HOME.CSS
   Used by: index.html and Admin.html.
   Contains: header, product grid / cards, product form, buttons.
   Admin.css is loaded after this file and builds on it.

   Variables, reset, .hidden and .toast live in base.css.
   ============================================================= */



/* -------------------------------------------------------------
   HEADER
   ------------------------------------------------------------- */
.header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
  padding: var(--header-padding);
  background-color: var(--color-header-bg);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.25);
}

.header-logo {
  color: var(--color-on-dark);
  font-size: var(--fs-logo);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header-logo-text-2 {
  color: var(--color-primary-on-dark);
}

/* Cart icon and item count */
.cart-box {
  position: relative;
  display: inline-flex;
  padding: var(--space-2xs);
  border-radius: var(--radius-sm);
}

.cart-box-icon {
  width: var(--cart-icon-size);
  height: var(--cart-icon-size);
  fill: var(--color-on-dark);
  transition: transform var(--transition), fill var(--transition);
}

.cart-box:hover .cart-box-icon:hover {
  transform: scale(1.15);
  fill: var(--color-primary-on-dark);
}

.cart-box-count {
  position: absolute;
  top: -6px;
  right: -8px;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 var(--space-2xs);
  border-radius: var(--radius-pill);
  color: var(--color-warning);
  font-size: var(--fs-lg);
  font-weight: 700;
}



/* -------------------------------------------------------------
   SEARCH BAR (index.html only: it sits directly inside <main>)
   ------------------------------------------------------------- */
main > .product-form-field {
  padding: 0 var(--space-md);
}


/* -------------------------------------------------------------
   PRODUCT GRID
   ------------------------------------------------------------- */
.products-section {
  margin-bottom: var(--space-xl);
  padding-top: var(--space-lg);
}

.section-title {
  margin-bottom: var(--space-md);
  padding: 0 var(--space-md);
  font-size: 1.35rem;
  font-weight: 700;
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
  padding: 0 var(--space-md);
}


/* -------------------------------------------------------------
   PRODUCT CARD
   ------------------------------------------------------------- */
.product-card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  transition: transform var(--transition), box-shadow var(--transition);
}

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

.product-card-link {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: var(--space-3xs);
}

.product-card-media {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  background-color: var(--color-border);
}

.product-card-media-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.4s ease;
}

.product-card-badge {
  position: absolute;
  top: var(--space-xs);
  left: var(--space-xs);
  padding: var(--space-3xs) var(--space-xs);
  border-radius: var(--radius-sm);
  background-color: var(--color-danger);
  color: var(--color-surface);
  font-size: var(--fs-xs);
  font-weight: 700;
}

.product-card-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-3xs);
  padding: var(--space-sm);
}

.product-card-category {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
}

/* Name is limited to 2 lines so all cards keep the same height */
.product-card-name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.3;
}

.product-card-price {
  display: flex;
  align-items: baseline;
  gap: var(--space-xs);
  margin-top: var(--space-2xs);
}

.product-card-price-current {
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--color-primary);
}

.product-card-price-old {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  text-decoration: line-through;
}

/* "Add to cart" button */
.product-card-cart-btn {
  margin: 0 var(--space-sm) var(--space-sm);
  padding: var(--space-xs) var(--space-sm);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-sm);
  color: var(--color-primary);
  font-size: var(--fs-xs);
  font-weight: 700;
  transition: background-color var(--transition), color var(--transition),
    transform var(--transition);
}

.product-card-cart-btn:hover {
  background-color: var(--color-primary);
  color: var(--color-surface);
}

.product-card-cart-btn:active {
  transform: scale(0.97);
}

.product-card-cart-btn:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}


/* -------------------------------------------------------------
   BUTTONS
   .btn         = primary button
   #form-cancel-btn = secondary button (Cancel in the product form)
   ------------------------------------------------------------- */
.btn {
  min-height: 46px;
  padding: var(--space-sm) var(--space-lg);
  background-color: var(--color-primary);
  border-radius: var(--radius-sm);
  color: var(--color-surface);
  font-weight: 700;
  transition: background-color var(--transition), transform var(--transition);
}

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

.btn:active {
  transform: scale(0.98);
}

.btn:focus-visible {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 2px;
}

.btn:disabled {
  background-color: var(--color-border-strong);
  cursor: not-allowed;
  transform: none;
}

#form-cancel-btn {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  color: var(--color-text-soft);
}

#form-cancel-btn:hover {
  background-color: var(--color-surface-alt);
}


/* -------------------------------------------------------------
   ADMIN HEADER AND SECTIONS (Admin.html)
   ------------------------------------------------------------- */
.admin-cart {
  fill: var(--color-primary-on-dark);
}

.admin-welcome {
  color: var(--color-on-dark);
  font-size: var(--fs-logo);
  font-weight: 600;
}

.admin-header {
  justify-content: center;
  gap: var(--space-sm);
}

.add-product-dynamically,
.remove-product-dynamically {
  margin: var(--space-md);
  padding: var(--space-sm);
}


/* -------------------------------------------------------------
   PRODUCT FORM (modal dialog; shown / hidden with .hidden)
   ------------------------------------------------------------- */
.product-form {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: var(--z-modal);
  transform: translate(-50%, -50%);

  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  width: calc(100% - (var(--space-md) * 2));
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;      /* scroll inside the form on short screens */
  padding: var(--space-lg);

  background-color: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
}

.product-form-title {
  font-size: var(--fs-lg);
  font-weight: 700;
}

.product-form-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2xs);
}

.product-form-label {
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--color-text);
}

.product-form-input {
  width: 100%;
  min-height: 44px;
  padding: var(--space-xs) var(--space-sm);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
  transition: border-color var(--transition), box-shadow var(--transition);
}

/* The ".product-form__*" selectors are not used by the current HTML.
   They are kept so nothing is removed; the real class is listed with them. */
.product-form-input::placeholder,
.product-form__input::placeholder {
  color: var(--color-text-muted);
}

.product-form-input:hover,
.product-form__input:hover {
  border-color: var(--color-primary);
}

.product-form-input:focus,
.product-form__input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-focus-ring);
}


/* -------------------------------------------------------------
   RESPONSIVE
   Mobile first. Two breakpoints used across the project:
   640px (tablet) and 960px (desktop).
   ------------------------------------------------------------- */

/* Tablet: 640px and up */
@media (min-width: 640px) {
  .product-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .add-product-dynamically,
  .remove-product-dynamically {
    margin: var(--space-lg);
    padding: var(--space-lg);
  }

  .product-form {
    padding: var(--space-xl);
  }

  .product-form__row {
    flex-direction: row;
  }

  .product-form__row .product-form__field {
    flex: 1 1 0;
  }
}

/* Desktop: 960px and up */
@media (min-width: 960px) {
  .product-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-lg);
  }
}
