:root {
  --bg: #f5f7f6;
  --surface: #fff;
  --ink: #1f2523;
  --muted: #6d7571;
  --line: #e2ded6;
  --primary: #27745d;
  --primary-dark: #1f5d4b;
  --accent: #2f80c0;
  --warn: #c77929;
  --danger: #b94a48;
  --shadow: 0 14px 36px rgba(31, 37, 35, .08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Tahoma, Arial, sans-serif;
  line-height: 1.7;
}
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, textarea, select { font: inherit; }

.container {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.store-nav, .admin-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 70px;
  padding: 12px max(16px, calc((100vw - 1180px) / 2));
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand, .admin-top > div {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-weight: 800;
}
.brand img {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
}
.cart-link, .admin-top nav a, .nav-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  color: var(--ink);
  background: #eef7f3;
  border: 1px solid #cbe3d8;
  border-radius: 8px;
  cursor: pointer;
}
.cart-link b {
  display: grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  color: #fff;
  background: var(--primary);
  border-radius: 999px;
}

.search-box {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin: 24px 0 14px;
}
input, textarea, select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,128,192,.12); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  color: #fff;
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary, .btn.ghost {
  color: var(--primary);
  background: #eef7f3;
  border-color: #cbe3d8;
}
.btn:disabled, button:disabled { opacity: .55; cursor: not-allowed; }

.store-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 18px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(31,37,35,.05);
}
.store-summary > div {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}
.store-summary small {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(185,74,72,.12);
}
.status-dot.open {
  background: var(--primary);
  box-shadow: 0 0 0 4px rgba(39,116,93,.14);
}
.store-info-modal {
  width: min(620px, calc(100% - 24px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(31,37,35,.24);
}
.store-info-modal::backdrop { background: rgba(31,37,35,.36); }
.modal-close {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  font-size: 22px;
}
.store-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin: 12px 0 22px;
}
.store-strip.compact {
  grid-template-columns: repeat(2, 1fr);
  margin-bottom: 12px;
}
.store-strip div, .status-card {
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.store-strip span, .status-card span, .detail-list span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.slider {
  position: relative;
  height: clamp(210px, 34vw, 420px);
  overflow: hidden;
  background: #dde7e1;
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.slider-track, .slide {
  width: 100%;
  height: 100%;
}
.slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity .4s ease;
}
.slide.active { opacity: 1; z-index: 1; }
.slide img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.slide strong {
  position: absolute;
  right: 28px;
  bottom: 24px;
  color: #fff;
  font-size: clamp(22px, 4vw, 44px);
  text-shadow: 0 3px 20px rgba(0,0,0,.35);
}
.slider-btn {
  position: absolute;
  top: 50%;
  z-index: 2;
  width: 42px;
  height: 42px;
  transform: translateY(-50%);
  color: #fff;
  background: rgba(0,0,0,.28);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-size: 30px;
}
.slider-btn.prev { right: 14px; }
.slider-btn.next { left: 14px; }

.section-block { margin: 32px 0; }
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(24px, 3vw, 34px); }
h2 { font-size: 22px; }
h3 { font-size: 17px; }

.product-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.h-scroll {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(220px, 270px);
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.product-card {
  display: flex;
  flex-direction: column;
  min-height: 390px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 8px 22px rgba(31,37,35,.05);
  transition: transform .18s ease, box-shadow .18s ease;
}
.product-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 32px rgba(31,37,35,.09);
}
.product-media { aspect-ratio: 4 / 3; background: #e9ece7; overflow: hidden; }
.product-media img { width: 100%; height: 100%; object-fit: cover; }
.product-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  padding: 13px;
}
.product-body h3 { min-height: 58px; margin: 0; }
.eyebrow { color: var(--accent); font-size: 12px; font-weight: 700; }
.price-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.old-price { color: var(--muted); text-decoration: line-through; font-size: 13px; }
.stock { color: var(--primary); font-size: 13px; }
.muted { color: var(--muted); }

.qty-control {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  width: 100%;
  margin-top: auto;
  overflow: hidden;
  border: 1px solid #cbe3d8;
  border-radius: 8px;
}
.qty-control form { margin: 0; }
.qty-control button {
  width: 100%;
  height: 42px;
  color: var(--primary);
  background: #eef7f3;
  border: 0;
  cursor: pointer;
  font-size: 20px;
}
.qty-control span { text-align: center; font-weight: 800; }
.qty-control.compact {
  width: 136px;
  margin: 0;
}

.category-grid, .card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.category-card, .small-card {
  position: relative;
  min-height: 140px;
  overflow: hidden;
  color: #fff;
  background: #ddd;
  border-radius: 8px;
}
.category-card img, .small-card img {
  width: 100%;
  height: 100%;
  min-height: 140px;
  object-fit: cover;
}
.category-card span {
  position: absolute;
  right: 14px;
  bottom: 12px;
  font-weight: 800;
  text-shadow: 0 2px 12px rgba(0,0,0,.34);
}
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 24px 0;
}
.pagination a {
  display: grid;
  place-items: center;
  min-width: 38px;
  height: 38px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.pagination a.active { color: #fff; background: var(--primary); }

.split-layout {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 18px;
  margin-top: 24px;
  margin-bottom: 42px;
}
.panel {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.cart-list { display: grid; gap: 12px; }
.cart-item {
  display: grid;
  grid-template-columns: 90px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  background: #fbfaf7;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.cart-item img {
  width: 90px;
  height: 74px;
  object-fit: cover;
  border-radius: 8px;
}
.totals {
  display: grid;
  gap: 8px;
  margin-top: 18px;
}
.totals div, .detail-list div {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.totals .grand { font-size: 18px; border-bottom: 0; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.form-grid .wide, .wide { grid-column: 1 / -1; }
.check {
  display: flex !important;
  flex-direction: row;
  align-items: center;
  gap: 8px !important;
}
.check input { width: auto; min-height: auto; }
.map-row {
  display: grid;
  grid-template-columns: auto 1fr 1fr;
  gap: 10px;
}
.alert {
  margin: 0 0 12px;
  padding: 12px 14px;
  background: #f3f6fb;
  border: 1px solid #d8e3f4;
  border-radius: 8px;
}
.alert.success { background: #edf8f3; border-color: #c9e6d8; color: #1f5d4b; }
.alert.error { background: #fff1ef; border-color: #f2c9c3; color: var(--danger); }
.empty { color: var(--muted); }
.hidden { display: none !important; }
.warn-text { color: var(--warn); }
.danger-text { color: var(--danger); }
.badge {
  display: inline-flex;
  margin-right: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.badge.warn { color: #7a4a12; background: #fff4df; }
.badge.danger { color: #7e2725; background: #ffe8e5; }
.cart-control-wrap { margin-top: auto; }
.cart-control-wrap.is-loading { opacity: .65; pointer-events: none; }
.status-card.is-updated, .order-card.is-updated {
  animation: statusPulse 900ms ease;
}
@keyframes statusPulse {
  0% { box-shadow: 0 0 0 0 rgba(39, 116, 93, .28); }
  100% { box-shadow: 0 0 0 12px rgba(39, 116, 93, 0); }
}

.invoice-head, .order-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}
.status-card {
  display: grid;
  gap: 4px;
  margin: 16px 0;
  background: #eef7f3;
}
.table-wrap { width: 100%; overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
}
th, td {
  padding: 11px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  vertical-align: middle;
}
th { color: var(--muted); font-size: 13px; }
.late-box {
  margin-top: 16px;
  padding: 12px;
  border: 1px solid #f0d2ae;
  border-radius: 8px;
  background: #fff8ef;
}

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}
.auth-card {
  width: min(440px, 100%);
  padding: 24px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}
.hint { color: var(--muted); font-size: 13px; }
.auth-links {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
}

.admin-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  width: min(1380px, calc(100% - 32px));
  margin: 22px auto 48px;
}
.side-nav {
  position: sticky;
  top: 92px;
  display: grid;
  align-content: start;
  gap: 8px;
  height: max-content;
}
.side-nav a {
  padding: 12px 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.side-nav a.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}
.admin-content {
  min-width: 0;
  padding: 20px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.metric-card {
  padding: 16px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(31,37,35,.04);
}
.metric-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}
.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
}
.metric-card.warn { border-color: #f0d2ae; background: #fffaf2; }
.metric-card.danger { border-color: #f2c9c3; background: #fff7f6; }
.dashboard-panels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.dash-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
}
.inventory-alert, .courier-status-row, .late-order-row {
  display: grid;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.inventory-alert {
  grid-template-columns: 1fr auto;
}
.inventory-alert span, .courier-status-row span, .courier-status-row small {
  color: var(--muted);
  font-size: 13px;
}
.inventory-alert strong {
  color: var(--warn);
  grid-row: 1 / span 2;
  grid-column: 2;
  align-self: center;
}
.late-order-row {
  grid-template-columns: 1fr auto;
  color: var(--ink);
}
.quick-filter {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr auto auto auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
}
.quick-filter label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}
.inline-input {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}
.stock-adjust-form {
  display: grid;
  grid-template-columns: 76px 120px auto;
  gap: 6px;
  min-width: 250px;
}
.stock-adjust-form input { min-height: 36px; padding: 7px 8px; }
.stock-adjust-form button {
  color: var(--primary);
  background: #eef7f3;
  border: 1px solid #cbe3d8;
  border-radius: 8px;
  cursor: pointer;
}
.order-edit-panel {
  margin: 12px 0;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.order-edit-panel summary {
  cursor: pointer;
  font-weight: 800;
}
.order-item-edit {
  display: grid;
  grid-template-columns: 1fr 90px auto;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
}
.ready-messages {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}
.print-page {
  min-height: 100vh;
  padding: 24px;
  background: #eef1ef;
}
.print-sheet {
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 24px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.print-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}
.admin-form {
  padding: 14px;
  margin-bottom: 20px;
  background: #fbfaf7;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.mini-form { display: inline; margin-right: 8px; }
.mini-form button {
  color: var(--danger);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.thumb {
  width: 62px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
}
.small-card {
  min-height: auto;
  padding: 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}
.small-card img {
  height: 140px;
  min-height: auto;
  border-radius: 6px;
}
.wide-image img { height: 190px; }
.order-stack { display: grid; gap: 14px; }
.order-card {
  padding: 16px;
  background: #fbfaf7;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.compact-list {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0 18px;
}
.mini-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}
.mini-items span {
  padding: 6px 9px;
  background: #eef2f6;
  border-radius: 999px;
  font-size: 13px;
}
.notes {
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.notes p { margin: 4px 0; }
.note-form input { flex: 1 1 260px; }

@media (max-width: 980px) {
  .store-strip, .product-grid, .category-grid, .card-grid, .metric-grid, .dashboard-panels { grid-template-columns: repeat(2, 1fr); }
  .split-layout, .admin-layout { grid-template-columns: 1fr; }
  .quick-filter { grid-template-columns: repeat(2, 1fr); }
  .side-nav {
    position: static;
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 640px) {
  .container { width: min(100% - 20px, 1180px); }
  .store-nav, .admin-top {
    min-height: 62px;
    padding: 10px;
  }
  .admin-top { align-items: flex-start; }
  .admin-top nav { display: flex; gap: 6px; }
  .search-box, .form-grid, .map-row, .cart-item, .compact-list { grid-template-columns: 1fr; }
  .store-summary { align-items: stretch; flex-direction: column; }
  .store-summary > div { width: 100%; }
  .store-strip, .store-strip.compact { grid-template-columns: 1fr; }
  .product-grid, .category-grid, .card-grid, .metric-grid, .dashboard-panels, .quick-filter, .order-item-edit { grid-template-columns: 1fr; }
  .stock-adjust-form { grid-template-columns: 1fr; min-width: 0; }
  .h-scroll { grid-auto-columns: minmax(220px, 82vw); }
  .slider { height: 230px; }
  .product-card { min-height: 360px; }
  .product-body h3 { min-height: auto; }
  .cart-item img { width: 100%; height: 160px; }
  .side-nav { grid-template-columns: repeat(2, 1fr); }
  .invoice-head, .order-head { flex-direction: column; }
  .inline-form > * { flex: 1 1 100%; }
  .product-table table, .product-table thead, .product-table tbody, .product-table tr, .product-table td { display: block; }
  .product-table thead { display: none; }
  .product-table tr {
    margin-bottom: 12px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
  }
  .product-table td {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--line);
  }
  .product-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
  }
}

@media print {
  body { background: #fff; }
  .no-print, .store-nav, .admin-top, .side-nav { display: none !important; }
  .container, .split-layout { width: 100%; display: block; margin: 0; }
  .panel { box-shadow: none; border: 0; }
  .print-page { padding: 0; background: #fff; }
  .print-sheet { width: 100%; border: 0; padding: 0; }
}
