/* ==========================================================================
   Silk & Loom — Walmart-inspired design system
   Desktop-first storefront + fully responsive mobile + admin skin + RTL
   ========================================================================== */

:root {
  --wm-blue: #0071dc;
  --wm-blue-dark: #004f9a;
  --wm-blue-deep: #041e42;
  --wm-yellow: #ffc220;
  --wm-yellow-dark: #e6a900;
  --wm-red: #e11b22;
  --wm-green: #2e7d32;
  --wm-ink: #2e2f32;
  --wm-gray-1: #f6f6f6;
  --wm-gray-2: #e6e6e6;
  --wm-gray-3: #c9c9c9;
  --wm-gray-4: #74767c;
  --wm-radius: 8px;
  --wm-shadow: 0 2px 8px rgba(0, 0, 0, .12);
  --wm-max: 1280px;
}

* { box-sizing: border-box; }

html {
  font-size: 15px;
  position: relative;
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: rgba(0, 113, 220, .15);
}

@media (min-width: 768px) {
  html { font-size: 16px; }
}

body {
  margin: 0;
  font-family: "Segoe UI", -apple-system, "Helvetica Neue", "Noto Sans", "Noto Sans SC", "Noto Sans TC", "Noto Sans Arabic", Arial, sans-serif;
  color: var(--wm-ink);
  background: #fff;
  line-height: 1.45;
}

a { color: var(--wm-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.2; margin: 0 0 .6rem; color: var(--wm-ink); }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }

img { max-width: 100%; height: auto; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--wm-yellow);
  color: var(--wm-blue-deep);
  padding: .5rem 1rem;
  z-index: 200;
}
.skip-link:focus { left: 0; }

/* ==========================================================================
   Storefront header — blue masthead + department bar
   ========================================================================== */

.wm-header {
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--wm-shadow);
}

.wm-masthead {
  background: var(--wm-blue);
  color: #fff;
}

.wm-masthead-inner {
  max-width: var(--wm-max);
  margin: 0 auto;
  padding: .55rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.wm-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: #fff;
  font-weight: 700;
  font-size: 1.25rem;
  white-space: nowrap;
}
.wm-brand:hover { text-decoration: none; }

.wm-brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  width: 26px;
  height: 26px;
}
.wm-brand-mark i { background: var(--wm-yellow); border-radius: 50% 50% 50% 0; }
.wm-brand-mark i:nth-child(2) { border-radius: 50%; }
.wm-brand-mark i:nth-child(3) { border-radius: 50% 50% 0 50%; }
.wm-brand-mark i:nth-child(4) { border-radius: 50% 0 50% 50%; }
.wm-brand-mark i:nth-child(5) { border-radius: 50%; }
.wm-brand-mark i:nth-child(6) { border-radius: 0 50% 50% 50%; }

.wm-search {
  flex: 1 1 auto;
  display: flex;
  max-width: 720px;
  background: #fff;
  border-radius: 999px;
  overflow: hidden;
  border: 2px solid transparent;
}
.wm-search:focus-within { border-color: var(--wm-yellow); }
.wm-search input {
  flex: 1;
  border: 0;
  padding: .55rem 1rem;
  font-size: .95rem;
  outline: none;
  min-width: 0;
}
.wm-search button {
  border: 0;
  background: var(--wm-blue);
  color: #fff;
  padding: 0 .9rem;
  font-size: 1rem;
  cursor: pointer;
}
.wm-search button:hover { background: var(--wm-blue-dark); }

.wm-masthead-actions {
  display: flex;
  align-items: center;
  gap: .35rem;
  margin-inline-start: auto;
}

.wm-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #fff;
  font-size: .68rem;
  line-height: 1.1;
  padding: .25rem .5rem;
  border-radius: var(--wm-radius);
}
.wm-action:hover { background: rgba(255, 255, 255, .14); text-decoration: none; }
.wm-action-ico { font-size: 1.15rem; font-style: normal; }

.wm-lang select {
  border: 0;
  border-radius: var(--wm-radius);
  padding: .3rem .35rem;
  font-size: .78rem;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  max-width: 110px;
}
.wm-lang select option { color: var(--wm-ink); }

.wm-cart { position: relative; }

/* burger hidden on desktop */
.wm-burger {
  display: none;
  flex-direction: column;
  gap: 4px;
  background: none;
  border: 0;
  padding: .4rem;
  cursor: pointer;
}
.wm-burger span {
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
}

/* Department bar */
.wm-departments {
  background: var(--wm-blue-dark);
}

.wm-departments-inner {
  max-width: var(--wm-max);
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  flex-wrap: wrap;
}

.wm-departments a {
  color: #fff;
  padding: .5rem .9rem;
  font-size: .88rem;
  font-weight: 600;
}
.wm-departments a:hover {
  background: rgba(255, 255, 255, .14);
  text-decoration: none;
  border-radius: 0 0 var(--wm-radius) var(--wm-radius);
}

/* Mobile drawer */
.wm-drawer { display: none; }

/* ==========================================================================
   Layout containers
   ========================================================================== */

.container {
  max-width: var(--wm-max);
  margin: 0 auto;
  padding: 1.25rem 1rem 3rem;
}

.muted { color: var(--wm-gray-4); }

/* Flash / error banners */
.flash {
  background: #e7f4e8;
  border: 1px solid var(--wm-green);
  color: var(--wm-green);
  padding: .65rem 1rem;
  border-radius: var(--wm-radius);
  margin: .75rem auto 0;
  max-width: var(--wm-max);
  font-weight: 600;
}
.error, .admin-banner {
  background: #fdeaea;
  border: 1px solid var(--wm-red);
  color: var(--wm-red);
  padding: .65rem 1rem;
  border-radius: var(--wm-radius);
  margin: .75rem auto 0;
  max-width: var(--wm-max);
  font-weight: 600;
}

/* Validation */
.validation-summary-errors {
  background: #fdeaea;
  border: 1px solid var(--wm-red);
  color: var(--wm-red);
  border-radius: var(--wm-radius);
  padding: .65rem 1rem;
  margin-bottom: 1rem;
  font-weight: 600;
}
.field-validation-error { color: var(--wm-red); font-size: .85rem; }
.input-validation-error { border-color: var(--wm-red) !important; }

/* ==========================================================================
   Buttons — round pill style
   ========================================================================== */

.button {
  display: inline-block;
  border: 1px solid var(--wm-gray-3);
  background: #fff;
  color: var(--wm-ink);
  border-radius: 999px;
  padding: .5rem 1.25rem;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: box-shadow .12s ease;
}
.button:hover { box-shadow: var(--wm-shadow); text-decoration: none; }

.button.primary {
  background: var(--wm-yellow);
  border-color: var(--wm-yellow);
  color: var(--wm-blue-deep);
}
.button.primary:hover { background: var(--wm-yellow-dark); border-color: var(--wm-yellow-dark); }

.button.small { padding: .3rem .85rem; font-size: .82rem; }

.button.danger { border-color: var(--wm-red); color: var(--wm-red); }

.inline { display: inline; }

/* ==========================================================================
   Forms
   ========================================================================== */

label { font-weight: 600; font-size: .9rem; display: block; margin: .8rem 0 .25rem; }

input[type="text"], input[type="search"], input[type="email"], input[type="number"],
input[type="password"], input[type="tel"], input[type="date"], input[type="datetime-local"],
select, textarea {
  width: 100%;
  max-width: 420px;
  padding: .5rem .65rem;
  border: 1px solid var(--wm-gray-3);
  border-radius: var(--wm-radius);
  font: inherit;
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--wm-blue);
  box-shadow: 0 0 0 3px rgba(0, 113, 220, .18);
}

/* ==========================================================================
   Hero + product grid (storefront)
   ========================================================================== */

.hero {
  background: linear-gradient(120deg, var(--wm-blue-deep), var(--wm-blue));
  color: #fff;
  border-radius: var(--wm-radius);
  padding: 2rem 1.5rem;
  margin-bottom: 1.5rem;
}
.hero h1 { color: #fff; margin-bottom: .2rem; }
.hero .lead { color: #dbe9f7; font-size: 1.05rem; margin: 0; }

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

.product-card {
  border: 1px solid var(--wm-gray-2);
  border-radius: var(--wm-radius);
  overflow: hidden;
  background: #fff;
  display: flex;
  flex-direction: column;
  transition: box-shadow .15s ease, transform .15s ease;
}
.product-card:hover {
  box-shadow: var(--wm-shadow);
  transform: translateY(-2px);
}

.product-card .product-image {
  aspect-ratio: 4 / 3;
  width: 100%;
  object-fit: cover;
  background: var(--wm-gray-1);
  border: 0;
  display: block;
}

.product-card .product-body {
  padding: .7rem .8rem .9rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  flex: 1;
}
.product-card h3 { margin: 0; font-size: .98rem; }
.product-card h3 a { color: var(--wm-ink); }
.product-card h3 a:hover { color: var(--wm-blue); }
.product-card .material { color: var(--wm-gray-4); font-size: .82rem; margin: 0; }

.product-card .price { margin: .3rem 0 0; font-weight: 700; font-size: 1.1rem; }
.product-card .price s { color: var(--wm-gray-4); font-weight: 400; font-size: .85rem; margin-inline-start: .4rem; }

.price-new { color: var(--wm-red); }

.stock { color: var(--wm-green); font-size: .82rem; font-weight: 600; margin: .2rem 0 0; }
.stock.out { color: var(--wm-red); }

/* Legacy swatch fallback (no image) */
.product-swatch {
  aspect-ratio: 4 / 3;
  background: linear-gradient(135deg, var(--wm-gray-2), var(--wm-gray-1));
}
.product-swatch.large { min-height: 260px; border-radius: var(--wm-radius); }

/* ==========================================================================
   Product detail
   ========================================================================== */

.product-detail {
  display: grid;
  grid-template-columns: minmax(280px, 480px) 1fr;
  gap: 2rem;
  align-items: start;
}
.product-detail .product-image-large {
  width: 100%;
  border: 1px solid var(--wm-gray-2);
  border-radius: var(--wm-radius);
  background: var(--wm-gray-1);
}
.product-detail .price { font-size: 1.6rem; font-weight: 700; }

/* ==========================================================================
   Tables (cart, admin)
   ========================================================================== */

.cart-table, table.data, .admin table, table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}

.cart-table th, .cart-table td,
table th, table td {
  text-align: start;
  padding: .6rem .7rem;
  border-bottom: 1px solid var(--wm-gray-2);
  vertical-align: middle;
}

.cart-table th, table th {
  background: var(--wm-gray-1);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--wm-gray-4);
}

.cart-summary {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--wm-gray-2);
  border-radius: var(--wm-radius);
  max-width: 480px;
  background: var(--wm-gray-1);
}
.cart-summary dt { font-weight: 600; margin-top: .35rem; }
.cart-summary dd { margin: 0 0 .35rem; }
.cart-summary .grand { font-size: 1.15rem; font-weight: 700; }

.badge {
  display: inline-block;
  background: var(--wm-blue);
  color: #fff;
  border-radius: 999px;
  padding: .15rem .7rem;
  font-size: .78rem;
  font-weight: 700;
  vertical-align: middle;
}
.badge.gray { background: var(--wm-gray-4); }
.badge.green { background: var(--wm-green); }
.badge.red { background: var(--wm-red); }
.badge.yellow { background: var(--wm-yellow); color: var(--wm-blue-deep); }

/* ==========================================================================
   Footer
   ========================================================================== */

.wm-footer {
  background: var(--wm-blue-deep);
  color: #cfd8e3;
  margin-top: 2rem;
  padding: 2rem 1rem 2.5rem;
}

.wm-footer-cols {
  max-width: var(--wm-max);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.5rem;
}

.wm-footer h4 { color: #fff; font-size: .95rem; margin-bottom: .6rem; }
.wm-footer a { display: block; color: #cfd8e3; padding: .18rem 0; font-size: .88rem; }
.wm-footer a:hover { color: #fff; }
.wm-footer .muted { color: #8fa3b8; margin-top: .8rem; }

/* ==========================================================================
   Admin skin — deep-navy chrome on the same system
   ========================================================================== */

body.admin { background: var(--wm-gray-1); }

.admin-header { background: var(--wm-blue-deep); }

.admin-header .wm-masthead { background: transparent; }

.admin-header .wm-departments { background: #062b56; }

.admin .flash { margin-inline: auto; max-width: var(--wm-max); }

.admin .container { padding-top: 1.5rem; }

/* ==========================================================================
   RTL support (Arabic)
   ========================================================================== */

[dir="rtl"] .wm-brand-mark i:first-child { border-radius: 0 50% 50% 50%; }
[dir="rtl"] .wm-brand-mark i:last-child { border-radius: 50% 50% 50% 0; }

/* ==========================================================================
   Tablet
   ========================================================================== */

@media (max-width: 900px) {
  .product-detail { grid-template-columns: 1fr; }
  .wm-search { max-width: none; }
}

/* ==========================================================================
   Mobile — iPhone/Android optimized
   ========================================================================== */

@media (max-width: 768px) {
  .wm-masthead-inner { flex-wrap: wrap; gap: .5rem; padding: .5rem .75rem; }

  /* Row 1: brand + actions + burger; Row 2: full-width search */
  .wm-search { order: 3; flex-basis: 100%; }
  .wm-search input { padding: .6rem 1rem; }
  .wm-search button { padding: 0 1.1rem; }

  .wm-lang { display: none; }

  .wm-action span:not(.wm-action-ico) { display: none; } /* icon-only actions */
  .wm-action { padding: .35rem; }

  .wm-burger { display: flex; margin-inline-start: .25rem; }

  .wm-departments { display: none; }

  .wm-drawer {
    display: none;
    flex-direction: column;
    background: var(--wm-blue-dark);
    border-top: 1px solid rgba(255, 255, 255, .15);
  }
  body.nav-open .wm-drawer { display: flex; }
  .wm-drawer a {
    color: #fff;
    padding: .85rem 1.25rem;
    font-size: .95rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
  }
  .wm-drawer a:last-child { border-bottom: 0; }

  .container { padding: 1rem .75rem 2.5rem; }

  .hero { padding: 1.4rem 1rem; }
  .hero h1 { font-size: 1.4rem; }

  /* 2-up product grid on phones */
  .product-grid { grid-template-columns: repeat(2, 1fr); gap: .6rem; }
  .product-card .product-body { padding: .55rem .6rem .7rem; }
  .product-card h3 { font-size: .88rem; }
  .product-card .price { font-size: 1rem; }

  h1 { font-size: 1.45rem; }
  h2 { font-size: 1.15rem; }

  /* Horizontal-scroll tables instead of squishing (container scrolls) */
  .container { overflow-x: auto; }
  .cart-table, table.data, .admin table, table { min-width: 560px; }

  .cart-summary { max-width: none; }

  /* Comfortable touch targets */
  .button { padding: .65rem 1.2rem; min-height: 44px; }
  .button.small { min-height: 36px; }
  input, select, textarea { min-height: 44px; max-width: none; }
  input[type="number"] { max-width: 130px; }

  .product-detail { gap: 1rem; }

  .button.primary { display: block; width: 100%; }

  .badge { font-size: .72rem; padding: .12rem .55rem; }

  /* iOS input zoom prevention */
  input, select, textarea { font-size: 16px; }
}

/* Very small phones */
@media (max-width: 380px) {
  .product-grid { grid-template-columns: 1fr; }
  .wm-brand-name { font-size: 1.05rem; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Tiered pricing ---------- */
.tier-table {
  margin-top: 1rem;
  border-collapse: collapse;
  width: 100%;
  max-width: 420px;
  font-size: .92rem;
}
.tier-table th, .tier-table td {
  border: 1px solid var(--border, #e5e7eb);
  padding: .3rem .6rem;
  text-align: left;
}
.tier-table th { background: var(--surface-alt, #f7f7f8); font-weight: 600; }
.tier-table tr.tier-current { background: #fff8e6; font-weight: 600; }

.tier-badge {
  display: inline-block;
  margin-inline-start: .5rem;
  padding: .05rem .5rem;
  border-radius: 999px;
  background: #e8f5e9;
  color: #1b5e20;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}

[dir="rtl"] .tier-badge { margin-inline-start: 0; margin-inline-end: .5rem; }

/* Long-form product description on the details page (imported wholesale copy). */
.product-description {
    max-width: 60ch;
    line-height: 1.55;
    color: var(--muted, #444);
    margin: 0.5rem 0 1rem;
}

/* Four-stage order progress tracker (customer order status page) */
.stage-track {
    display: flex;
    gap: 0;
    list-style: none;
    padding: 0;
    margin: 1rem 0;
    counter-reset: stage;
    flex-wrap: wrap;
}
.stage-track li {
    flex: 1 1 0;
    min-width: 80px;
    text-align: center;
    padding: 0.5rem 0.25rem;
    border-bottom: 3px solid #d0d0d0;
    color: var(--muted, #666);
    font-size: 0.85rem;
    position: relative;
}
.stage-track li.done {
    border-bottom-color: #1a73e8;
    color: #1a73e8;
    font-weight: 600;
}
.stage-track li.done::before { content: "\2713 "; }

/* Database-unavailable page (free-tier auto-pause graceful degradation) */
.unavailable-card {
    max-width: 560px;
    margin: 4rem auto;
    padding: 2rem;
    text-align: center;
    border: 1px solid var(--wm-border, #e5e5e5);
    border-radius: 12px;
    background: var(--wm-surface, #fff);
}

.unavailable-card h1 {
    font-size: 1.4rem;
    margin-bottom: 1rem;
}
