:root {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #172033;
  background: #f4f6fb;
  font-size: 16px;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --ink: #172033;
  --muted: #778197;
  --nav: #111b31;
  --green: #087f61;
  --line: #e5e9f1;
  --surface: #fff;
  --page-width: 1560px;
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--green); }
button, input, textarea, select { font: inherit; }
button, a { touch-action: manipulation; }
button:focus-visible, a:focus-visible, input:focus-visible,
textarea:focus-visible, summary:focus-visible {
  outline: 3px solid #55d6a3;
  outline-offset: 3px;
}

.site-header {
  min-height: 68px;
  background: var(--nav);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px clamp(16px, 4vw, 64px);
  position: relative;
  z-index: 20;
}
.brand {
  flex: 0 0 auto;
  font-size: clamp(20px, 1.6vw, 27px);
  font-weight: 850;
  color: white;
  text-decoration: none;
  letter-spacing: -.5px;
}
.brand span { color: #55d6a3; }
.site-nav {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px 18px;
  font-size: 13px;
}
.site-nav a { color: #e7edf7; text-decoration: none; }
.site-nav a:hover { color: #55d6a3; }
.site-nav form { margin: 0; }
.nav-user { color: #b9c4d5; }
.nav-toggle {
  display: none;
  width: 44px;
  height: 42px;
  padding: 9px;
  border: 1px solid #526078;
  background: transparent;
  border-radius: 9px;
}
.nav-toggle span {
  display: block;
  height: 2px;
  background: white;
  margin: 5px 0;
  border-radius: 2px;
}

.page-main {
  width: min(94%, var(--page-width));
  margin: clamp(22px, 3vw, 48px) auto;
  padding: 0 clamp(0px, 1vw, 12px);
  flex: 1;
  min-height: 70vh;
}
h1 { font-size: clamp(27px, 3vw, 46px); line-height: 1.12; margin: 8px 0 18px; }
h2 { font-size: clamp(19px, 1.8vw, 26px); margin-top: 0; }
h3 { font-size: clamp(16px, 1.4vw, 21px); }
p { line-height: 1.6; }
.eyebrow { font-size: 11px; letter-spacing: 1.7px; color: #168a69; font-weight: 800; }
.muted { color: var(--muted); font-size: 13px; }
.card, .product-form, .product-item, .shop-card, .catalogue-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 15px;
  box-shadow: 0 5px 20px #17203308;
}
.card { padding: clamp(16px, 2vw, 26px); margin: 18px 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,155px),1fr)); gap: 14px; }
.stats .card { margin: 0; }
.stats strong { display: block; font-size: clamp(24px,2.4vw,34px); margin-top: 9px; }
label { display: block; font-size: 13px; font-weight: 650; margin: 16px 0 7px; }
input, textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 11px 12px;
  border: 1px solid #dce2ec;
  border-radius: 8px;
  background: white;
  color: var(--ink);
}
textarea { resize: vertical; }
button, .linkbutton {
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  min-height: 42px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.primary { background: var(--green); color: white; }
.danger { background: #fff0f0; color: #b42318; }
.quiet { background: #263550; color: white; }
.full { width: 100%; margin-top: 20px; }
.small { font-size: 11px; padding: 7px 10px; margin: 2px; }
.auth { max-width: 440px; margin: 50px auto; }
.formcard { max-width: 680px; }
.back, .back-link { display: inline-block; margin: 8px 0 18px; color: #52617a; text-decoration: none; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid #edf0f5; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; }
.notice { padding: 13px; border-radius: 9px; margin: 12px 0; }
.success { background: #e8f8f1; color: #11664c; }
.error { background: #fff0f0; color: #a32222; }
.site-footer { text-align: center; padding: 26px 16px; color: #8791a4; font-size: 12px; }

/* Public marketplace */
.public-hero, .shop-hero {
  padding: clamp(22px, 4vw, 56px);
  border-radius: 20px;
  background: linear-gradient(120deg,#e5f7f0,#eef2ff);
  margin-bottom: clamp(22px,3vw,38px);
}
.public-hero h1, .shop-hero h1 { margin-bottom: 10px; }
.hero-copy { color: #5e6b80; max-width: 680px; }
.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill,minmax(min(100%,260px),1fr));
  gap: clamp(14px,2vw,22px);
}
.shop-card { padding: clamp(17px,2vw,24px); display: flex; gap: 16px; align-items: flex-start; min-width: 0; }
.shop-avatar {
  width: 58px; height: 58px; flex: 0 0 58px;
  display: grid; place-items: center;
  border-radius: 16px; background: #e6f7f0; color: #087f61;
  font-size: 25px; font-weight: 850;
}
.shop-card-content { min-width: 0; }
.shop-card h2 { overflow-wrap: anywhere; margin: 5px 0; }
.shop-card .linkbutton { margin-top: 8px; }
.catalogue-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 22px 0 14px; }
.catalogue-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill,minmax(min(100%,245px),1fr));
  gap: clamp(13px,1.8vw,22px);
}
.catalogue-card { padding: 15px; min-width: 0; }
.catalogue-image-button {
  display: grid; place-items: center;
  width: 100%; min-height: 112px;
  padding: 8px; background: #f5f7fa;
  border: 1px solid #edf0f5; border-radius: 11px;
}
.catalogue-thumb {
  width: 88px; height: 88px; object-fit: contain;
  display: block; border-radius: 7px;
}
.catalogue-placeholder {
  width: 100%; min-height: 112px; display: grid; place-items: center;
  background: #f5f7fa; border-radius: 11px; color: var(--muted);
  font-size: 13px;
}
.catalogue-info { padding-top: 10px; }
.catalogue-info h3 { margin: 4px 0 7px; overflow-wrap: anywhere; }
.product-description {
  color: #667085; font-size: 13px; line-height: 1.5;
  overflow-wrap: anywhere;
}
.catalogue-price { font-size: 18px; font-weight: 800; margin: 10px 0 5px; }
.stock-status, .sold-status { font-size: 12px; font-weight: 700; }
.stock-status { color: #087f61; }
.sold-status { color: #a15c12; }
.empty-state {
  text-align: center; padding: clamp(28px,5vw,60px);
  background: white; border: 1px dashed #cbd3df; border-radius: 16px;
}
.image-dialog {
  width: min(92vw,900px); max-width: 900px;
  border: 0; border-radius: 15px; padding: 16px;
}
.image-dialog::backdrop { background: #101828bb; }
.dialog-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
#publicImageLarge { display: block; max-width: 100%; max-height: 75vh; object-fit: contain; margin: 16px auto 0; }

/* Product management */
.products-wrap { max-width: 1400px; margin: auto; }
.product-layout { display: grid; grid-template-columns: minmax(260px,340px) minmax(0,1fr); gap: 22px; align-items: start; }
.product-form, .product-item { padding: 16px; min-width: 0; }
.product-form input, .product-form textarea, .product-item input, .product-item textarea { margin: 5px 0 12px; }
.product-list { display: grid; grid-template-columns: repeat(auto-fill,minmax(min(100%,260px),1fr)); gap: 14px; }
.product-head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.product-thumb, .product-placeholder {
  width: 88px; height: 88px; flex: 0 0 88px;
  object-fit: contain; background: #f1f3f5; border-radius: 10px;
}
.product-thumb { border: 1px solid #ddd; cursor: zoom-in; }
.product-placeholder { display: grid; place-items: center; color: #666; font-size: 12px; }
.product-meta { min-width: 0; }
.product-meta h3 { margin: 0 0 5px; overflow-wrap: anywhere; }
.product-price { font-weight: 700; margin: 4px 0; }
.product-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.product-edit { border-top: 1px solid #ddd; margin-top: 12px; padding-top: 10px; }
.product-empty { padding: 28px; text-align: center; border: 1px dashed #bbb; border-radius: 12px; }
.image-preview { max-width: 100%; max-height: 70vh; object-fit: contain; }
dialog { max-width: 94vw; border: 0; border-radius: 12px; padding: 16px; }
dialog::backdrop { background: #101828bb; }

@media (max-width: 1050px) {
  .site-header { align-items: flex-start; }
  .site-nav { gap: 9px 13px; }
  .product-layout { grid-template-columns: minmax(240px,300px) minmax(0,1fr); }
}

@media (max-width: 760px) {
  .site-header { min-height: 64px; align-items: center; flex-wrap: wrap; padding: 10px 16px; }
  .nav-toggle { display: block; }
  .site-nav {
    display: none; width: 100%; flex-direction: column; align-items: stretch;
    gap: 0; padding: 8px 0 4px;
  }
  .site-nav.nav-open { display: flex; }
  .site-nav a, .site-nav .nav-user { padding: 11px 8px; }
  .site-nav form { padding: 5px 8px; }
  .site-nav form button { width: 100%; }
  .page-main { width: min(94%,680px); margin: 22px auto; }
  .product-layout { grid-template-columns: 1fr; }
  .catalogue-grid { grid-template-columns: repeat(auto-fill,minmax(min(100%,210px),1fr)); }
}

@media (max-width: 480px) {
  .page-main { width: calc(100% - 28px); margin: 18px auto; }
  .public-hero, .shop-hero { padding: 22px 18px; border-radius: 14px; }
  .shop-card { gap: 12px; }
  .shop-avatar { width: 48px; height: 48px; flex-basis: 48px; }
  .catalogue-grid, .shop-grid, .product-list { grid-template-columns: 1fr; }
  .catalogue-card { display: grid; grid-template-columns: 104px minmax(0,1fr); gap: 12px; align-items: start; }
  .catalogue-image-button, .catalogue-placeholder { min-height: 104px; width: 104px; }
  .catalogue-info { padding-top: 0; }
  .catalogue-thumb { width: 88px; height: 88px; }
  .catalogue-info h3 { font-size: 16px; }
  .catalogue-price { font-size: 16px; }
  .catalogue-heading { align-items: flex-start; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
  .card { padding: 16px; }
}

@media (min-width: 1800px) {
  :root { font-size: 18px; }
  .page-main { width: min(92%,1900px); }
  .site-header { padding-left: max(4%,calc((100% - 1900px)/2)); padding-right: max(4%,calc((100% - 1900px)/2)); }
  .catalogue-grid { grid-template-columns: repeat(auto-fill,minmax(280px,1fr)); }
  .catalogue-card { padding: 20px; }
}

@media (min-width: 2600px) {
  :root { font-size: 20px; }
  .page-main { width: min(90%,2300px); }
  .catalogue-grid { grid-template-columns: repeat(auto-fill,minmax(320px,1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}


/* STAGE 6 RESPONSIVE PLATFORM LAYER */
html, body { max-width: 100%; overflow-x: clip; }
.page-main, .products-wrap, .card, section { min-width: 0; }
img, video, iframe { max-width: 100%; }
button, .linkbutton { min-height: 44px; }
input[type="checkbox"], input[type="radio"] {
  width: auto; min-height: auto; margin-right: 8px;
  accent-color: var(--green);
}
input[type="file"] { max-width: 100%; }
textarea { max-width: 100%; }
form { min-width: 0; }
.table-wrap {
  width: 100%; max-width: 100%;
  overflow-x: auto; overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
.table-wrap table { min-width: 620px; }
td, th { overflow-wrap: anywhere; }
.product-layout {
  grid-template-columns: minmax(0, 330px) minmax(0, 1fr);
}
.product-layout > *, .product-item, .product-form,
.product-meta, .catalogue-info { min-width: 0; }
.product-list {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
}
.product-form button, .product-actions button { max-width: 100%; }
.site-nav { min-width: 0; }
.site-nav a, .site-nav button { overflow-wrap: anywhere; }
.auth { width: min(100%, 440px); }
.formcard { width: min(100%, 680px); }
.image-dialog { max-height: 92vh; overflow: auto; }
#publicImageLarge, .image-preview { max-height: 76vh; }

@media (max-width: 1050px) {
  .site-header { gap: 12px; }
  .site-nav { gap: 8px 12px; }
  .product-layout {
    grid-template-columns: minmax(0, 280px) minmax(0, 1fr);
    gap: 16px;
  }
  .card { padding: clamp(14px, 2vw, 22px); }
}

@media (max-width: 760px) {
  .page-main { min-height: 60vh; }
  .site-header { position: relative; }
  .site-nav {
    max-height: 70vh; overflow-y: auto;
    overscroll-behavior: contain;
  }
  .product-layout { grid-template-columns: minmax(0, 1fr); }
  .product-list { grid-template-columns: minmax(0, 1fr); }
  .table-wrap table { min-width: 680px; }
  table:not(.table-wrap table) {
    display: block; width: 100%;
    overflow-x: auto; white-space: nowrap;
  }
  .stats { grid-template-columns: repeat(auto-fit, minmax(min(100%, 135px), 1fr)); }
  .stats .card { min-width: 0; }
  .auth { margin: 20px auto; }
  .product-form, .product-item { padding: 14px; }
  .product-actions form { max-width: 100%; }
}

@media (max-width: 480px) {
  .page-main { width: calc(100% - 24px); }
  .site-header { padding-inline: 12px; }
  .brand { font-size: 20px; }
  h1 { overflow-wrap: anywhere; }
  .card { padding: 14px; border-radius: 12px; }
  .stats { grid-template-columns: minmax(0, 1fr); }
  .product-head { align-items: flex-start; }
  .product-thumb, .product-placeholder {
    width: 76px; height: 76px; flex-basis: 76px;
  }
  .product-actions { align-items: stretch; }
  .product-actions form, .product-actions button { width: 100%; }
  .dialog-toolbar { flex-wrap: wrap; }
  .catalogue-card { min-width: 0; }
}

@media (min-width: 1400px) {
  .page-main { width: min(94%, 1700px); }
  .product-layout { grid-template-columns: minmax(300px, 360px) minmax(0, 1fr); }
  .product-list { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
}

@media (min-width: 1800px) {
  .page-main { width: min(92%, 2000px); }
  .site-header { padding-top: 18px; padding-bottom: 18px; }
  .card, .product-form, .product-item { padding: 24px; }
  .product-list { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
}

@media (min-width: 2600px) {
  :root { font-size: 21px; }
  .page-main { width: min(90%, 2400px); }
  .product-layout { grid-template-columns: minmax(360px, 440px) minmax(0, 1fr); }
  .product-list { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
}

/* WhatsApp connection page */
.whatsapp-card { width: min(100%, 760px); margin-inline: auto; }
.whatsapp-card form { margin-block: 1.25rem; }
.whatsapp-card input[type="tel"] {
  display: block; width: 100%; max-width: 420px;
  min-height: 46px; margin-block: .5rem 1rem;
}
.whatsapp-result {
  margin-block: 1.25rem; padding: 1rem;
  border: 1px solid var(--border, #64748b);
  border-radius: 12px; overflow-wrap: anywhere;
}
.whatsapp-qr {
  display: block; width: min(100%, 320px); height: auto;
  margin: 1rem auto; background: white; padding: 10px;
  border-radius: 8px;
}
.whatsapp-pairing-code {
  font-size: clamp(1.7rem, 7vw, 2.5rem);
  font-weight: 800; letter-spacing: .16em;
  overflow-wrap: anywhere;
}
.whatsapp-card button { max-width: 100%; }
@media (max-width: 480px) {
  .whatsapp-card { padding: 1rem; }
  .whatsapp-card button { width: 100%; }
}
