:root{
  --bg: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --soft: #f3f4f6;
}

*{ box-sizing: border-box; }

body{
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ===== Top bar ===== */
.topbar{
  position: sticky;
  top: 0;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.topbar-inner{
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand{
  font-size: 22px;
  margin: 0;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

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

/* Buttons */
.btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  background: #fff;
  font-weight: 600;
  white-space: nowrap;
}

.btn-small{ padding: 8px 10px; border-radius: 10px; font-weight: 700; }
.btn-active{ border-color: #9ca3af; background: #f9fafb; }

/* ===== Page layout ===== */
.page{
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 16px 30px;
}

.page-header h2{
  margin: 10px 0 6px;
  font-size: 30px;
}

.page-header p{
  margin: 0 0 18px;
  color: var(--muted);
}

/* Card */
.card{
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: #fff;
}

/* ===== Home category grid ===== */
.cat-grid{
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.cat-tile{
  text-decoration: none;
  color: inherit;
  text-align: center;
  padding: 10px 8px 14px;
  border-radius: 16px;
}

.cat-tile:hover{ background: #fafafa; }
.cat-tile:active{ transform: scale(0.99); }

.cat-icon{
  width: 124px;
  height: 124px;
  margin: 0 auto 12px;
  border-radius: 999px;
  background: var(--soft);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #374151;
}

.cat-label{
  font-size: 18px;
  font-weight: 700;
}

/* ===== Inputs + selects ===== */
.input{
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
}

.select{
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  font-size: 16px;
}

.label{
  display: block;
  font-weight: 700;
  margin: 0 0 6px;
}

.field{ margin: 0 0 14px; }
.muted{ color: var(--muted); font-size: 13px; }

/* Controls row (mobile) */
.controls{
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin: 10px 0 14px;
}

/* Layout */
.layout{ display: block; }

.filters{
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  background: #fff;
  margin-bottom: 14px;
}

.filters-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom: 12px;
}

.filters-actions{
  display:flex;
  gap:10px;
}

.results{ min-width: 0; }

.results-bar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin: 0 0 12px;
}

.toggle{ display:flex; gap:8px; }

/* Product cards */
.cards{ display: grid; gap: 12px; }

.product-card{
  display:flex;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  background: #fff;
}

.thumb{
  width: 64px;
  height: 64px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--soft);
  display:grid;
  place-items:center;
  font-weight: 900;
  color: #374151;
}

.pc-body{ flex: 1; min-width: 0; }
.pc-title{ font-weight: 900; margin-bottom: 4px; }
.pc-meta{ color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.pc-actions{ display:flex; gap:10px; flex-wrap: wrap; }

/* Selection + qty controls inside cards/tables */
.pc-selectrow{
  display:flex;
  gap: 12px;
  align-items:center;
  justify-content: space-between;
  margin: 10px 0 10px;
}

.check{
  display:flex;
  gap: 8px;
  align-items:center;
  font-weight: 700;
}

.qtybox{
  display:flex;
  gap: 8px;
  align-items:center;
}

.qty{
  width: 84px;
  padding: 10px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
}

/* Bulk action bar */
.bulkbar{
  display:flex;
  gap: 12px;
  align-items:center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.bulk-left{
  display:flex;
  flex-direction: column;
  gap: 2px;
}

.bulk-actions{
  display:flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Table */
.table-wrap{
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
}

.table{
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.table th, .table td{
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 14px;
}

.table thead th{
  position: sticky;
  top: 0;
  background: #fff;
}

.row-actions{
  display:flex;
  gap:8px;
  justify-content:flex-end;
}

/* Mobile overlay filters */
.overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 20;
}

/* ===== Modals ===== */
.modal-overlay{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 40;
}

.modal{
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(720px, calc(100vw - 28px));
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  z-index: 50;
  box-shadow: 0 18px 50px rgba(0,0,0,0.22);
}

.modal-header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap: 12px;
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--border);
}

.modal-kicker{
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.modal-title{
  margin: 4px 0 0;
  font-size: 20px;
}

.modal-body{
  padding: 14px;
}

.modal-footer{
  display:flex;
  gap: 10px;
  justify-content:flex-end;
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
}

/* Quick view key/values */
.kv-grid{
  display:grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.kv{
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  background: #fff;
}

.kv-k{
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.kv-v{
  margin-top: 6px;
  font-weight: 900;
}

/* ===== Responsive: Desktop upgrades (Home + general) ===== */
@media (min-width: 900px){
  .cat-grid{
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 22px;
  }

  .page{ padding: 26px 18px 40px; }

  .page-header h2{ font-size: 36px; }

  .cat-icon{
    width: 140px;
    height: 140px;
  }

  .cat-label{ font-size: 19px; }
}

/* Mobile filters: slide up panel */
@media (max-width: 899px){
  .filters{
    position: fixed;
    left: 0;
    right: 0;
    bottom: -100%;
    margin: 0;
    border-radius: 18px 18px 0 0;
    z-index: 30;
    max-height: 80vh;
    overflow: auto;
    transition: bottom 180ms ease;
  }
  .filters-close{ display: inline-flex; }
  .filters.filters-mobile-open{ bottom: 0; }

  /* Modal on phones: pin near bottom */
  .modal{
    top: auto;
    bottom: 14px;
    transform: translate(-50%, 0);
  }

  /* Bulk bar stacks better on phone */
  .bulkbar{
    flex-direction: column;
    align-items: stretch;
  }
  .bulk-actions{
    justify-content: flex-start;
  }
}

/* Desktop: real 2-column layout for category pages */
@media (min-width: 900px){
  .controls{ grid-template-columns: 1fr; }
  #openFilters{ display:none; }

  .layout{
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 18px;
    align-items: start;
  }

  .filters{
    position: sticky;
    top: 84px;
    margin-bottom: 0;
  }

  .filters-close{ display:none; }
}