@import url("https://fonts.googleapis.com/css2?family=Tajawal:wght@400;500;700;800&display=swap");

:root {
  --blue: #275b84;
  --blue-dark: #1f4b6f;
  --green: #67933f;
  --cream: #faf8f2;
  --text: #1f2933;
  --muted: #687386;
  --border: #e4e7ec;
  --soft-border: #eef1f5;
  --card: #ffffff;
  --danger: #b42318;
  --warning-bg: #fff7d6;
  --shadow: 0 18px 45px rgba(24, 38, 56, 0.08);
  --shadow-soft: 0 10px 28px rgba(24, 38, 56, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; scroll-behavior: smooth; }
body {
  font-family: "Tajawal", Tahoma, Arial, sans-serif;
  background: linear-gradient(180deg, var(--cream), #fff 55%);
  color: var(--text);
  line-height: 1.65;
}
a { color: inherit; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(28px, 4vw, 46px); color: var(--blue); line-height: 1.25; font-weight: 800; }
h2 { color: var(--blue); font-size: clamp(22px, 2.4vw, 32px); }
h3 { color: var(--blue); font-size: 20px; }

.container {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 60px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}
.hidden { display: none !important; }

/* Header */
.site-header {
  width: 100%;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 28px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.public-header { position: relative; z-index: 20; }
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 26px;
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  text-align: center;
}
.brand a { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.brand-logo {
  width: 185px;
  max-width: 36vw;
  height: auto;
  max-height: 82px;
  object-fit: contain;
  display: block;
  background: #fff;
  border-radius: 14px;
  padding: 4px;
}
.brand-text { text-align: center; }
.brand-text p,
.site-header p { color: var(--muted); margin-top: 6px; font-size: clamp(16px, 1.5vw, 20px); }
.last-update {
  display: inline-flex;
  margin-top: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(39, 91, 132, 0.08);
  color: var(--blue);
  font-weight: 700;
  font-size: 14px;
}

/* Buttons */
.btn,
.admin-link {
  border: 0;
  border-radius: 14px;
  background: var(--green);
  color: #fff;
  text-decoration: none;
  padding: 12px 18px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.btn:hover,
.admin-link:hover { transform: translateY(-1px); box-shadow: var(--shadow-soft); }
.btn-primary { background: var(--blue); }
.btn-danger { background: var(--danger); }
.btn-light { background: #eef4ea; color: var(--green); }
.secondary-link { color: var(--blue); font-weight: 800; text-decoration: none; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* Public page */
.public-container { margin-top: 36px; }
.toolbar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  padding: 18px;
  align-items: end;
}
.sticky-search {
  position: sticky;
  top: 12px;
  z-index: 15;
  backdrop-filter: blur(10px);
}
.search-box span,
.form-group span,
.rate-box span {
  display: block;
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 8px;
  font-weight: 700;
}
.search-control { position: relative; }
.search-control input { padding-inline-end: 44px; }
.clear-search {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: #eef1f5;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
input, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 14px;
  font: inherit;
  background: #fff;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus {
  border-color: rgba(39, 91, 132, .55);
  box-shadow: 0 0 0 4px rgba(39, 91, 132, .08);
}
input[type="checkbox"] { width: auto; transform: scale(1.2); }

.categories {
  display: flex;
  flex-wrap: nowrap;
  gap: 10px;
  margin: 18px 0 22px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  scrollbar-width: thin;
}
.chip {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(24, 38, 56, 0.04);
}
.chip b {
  display: inline-flex;
  min-width: 25px;
  height: 25px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(103, 147, 63, .12);
  color: var(--green);
  font-size: 13px;
  padding-inline: 7px;
}
.chip.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.chip.active b { background: rgba(255,255,255,.18); color: #fff; }

.table-card { overflow: hidden; }
.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
#countBadge, .badge {
  background: rgba(103, 147, 63, 0.12);
  color: var(--green);
  border-radius: 999px;
  padding: 7px 12px;
  font-weight: 800;
  white-space: nowrap;
}
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 15px 16px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  vertical-align: middle;
}
th { color: var(--blue); background: #fbfcfd; white-space: nowrap; font-size: 17px; }
.product-name { font-weight: 800; }
.category-name { color: var(--muted); }
.price { color: var(--green); font-weight: 800; white-space: nowrap; font-size: 18px; }
.mobile-item-no { display: none; }
.empty { padding: 34px; text-align: center; color: var(--muted); font-weight: 700; }
.small-note { color: var(--muted); font-size: 14px; line-height: 1.7; margin-top: 4px; }
.whatsapp-btn {
  display: inline-flex;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(103, 147, 63, .12);
  color: var(--green);
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

/* Admin */
.admin-header {
  justify-content: space-between;
  gap: 18px;
  padding-inline: clamp(16px, 5vw, 64px);
  text-align: right;
  position: sticky;
  top: 0;
  z-index: 30;
}
.admin-header .brand {
  margin: 0;
  justify-content: flex-start;
  max-width: none;
  width: auto;
  text-align: right;
}
.admin-header .brand-text { text-align: right; }
.admin-header h1 { font-size: clamp(24px, 3vw, 34px); }
.admin-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 18px;
  align-items: start;
}
.admin-panel { padding: 18px; }
.admin-panel h2, .admin-panel h3 { margin: 0 0 16px; }
.form-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)) auto; gap: 12px; align-items: end; }
.form-group { display: block; margin-bottom: 12px; }
.notice {
  padding: 12px 14px;
  border-radius: 14px;
  margin-bottom: 16px;
  background: rgba(103, 147, 63, 0.12);
  color: var(--green);
  font-weight: 800;
}
.error { background: rgba(180, 35, 24, 0.1); color: var(--danger); }
hr { border: 0; border-top: 1px solid var(--border); margin: 22px 0; }

.admin-filter-bar {
  display: grid;
  grid-template-columns: 1.4fr .8fr .8fr;
  gap: 12px;
  align-items: end;
  padding: 14px;
  margin-bottom: 16px;
  background: #fbfcfd;
  border: 1px solid var(--soft-border);
  border-radius: 18px;
}
.bulk-save-bar {
  padding-inline: 0 !important;
  align-items: center;
}
.bulk-save-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.bulk-save-footer {
  display: flex;
  justify-content: flex-end;
  padding: 18px 0 0;
}
.admin-table input,
.admin-table select { min-width: 120px; }
.admin-table .price-input { font-weight: 800; color: var(--green); }
.admin-table .is-dirty {
  background: var(--warning-bg);
  box-shadow: inset 4px 0 0 var(--green);
}
.admin-table .dirty-label {
  display: none;
  margin-inline-start: 8px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(103, 147, 63, .14);
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
}
.admin-table .is-dirty .dirty-label { display: inline-flex; }
.admin-save-dock {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(140%);
  width: min(720px, calc(100% - 28px));
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 22px 55px rgba(24, 38, 56, .18);
  z-index: 100;
  transition: transform .2s ease;
}
.admin-save-dock.show { transform: translateX(-50%) translateY(0); }
.admin-save-dock strong { color: var(--blue); }
.admin-save-dock div { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 18px; }
.login-card { width: min(420px, 100%); padding: 24px; }
.login-card h1 { margin-bottom: 8px; }
.login-card p { color: var(--muted); margin-bottom: 18px; }
.login-logo { width: 210px; max-width: 100%; display: block; margin: 0 auto 18px; }

/* Mobile */
@media (max-width: 900px) {
  .container { width: min(100% - 22px, 1180px); margin-top: 20px; }
  .site-header { padding: 30px 16px; }
  .brand { flex-direction: column; gap: 14px; }
  .brand-logo { width: 180px; max-width: 76vw; max-height: none; }
  .brand-text h1 { font-size: 31px; }
  .brand-text p { font-size: 18px; }
  .sticky-search { top: 8px; border-radius: 20px; }
  .categories { margin-top: 14px; }
  .table-head { align-items: flex-start; padding: 18px; }

  .public-products-table,
  .public-products-table thead,
  .public-products-table tbody,
  .public-products-table th,
  .public-products-table td,
  .public-products-table tr { display: block; }
  .public-products-table thead { display: none; }
  .public-products-table tbody { padding: 12px; background: #fbfcfd; }
  .public-products-table tr {
    margin: 0 0 12px;
    padding: 16px;
    background: #fff;
    border: 1px solid var(--soft-border);
    border-radius: 18px;
    box-shadow: 0 8px 20px rgba(24, 38, 56, 0.05);
  }
  .public-products-table td {
    border: 0;
    padding: 7px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
  }
  .public-products-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 800;
    flex: 0 0 auto;
  }
  .public-products-table .product-name {
    display: block;
    font-size: 20px;
    line-height: 1.45;
    padding-top: 0;
  }
  .public-products-table .product-name::before { content: none; }
  .mobile-item-no {
    display: inline-flex;
    margin-left: 8px;
    background: rgba(39, 91, 132, .08);
    color: var(--blue);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 13px;
    vertical-align: middle;
  }
  .public-products-table .price {
    justify-content: flex-end;
    font-size: 22px;
    color: var(--green);
    font-weight: 800;
  }
  .whatsapp-btn { width: 100%; justify-content: center; margin-top: 4px; }

  .admin-header { position: static; justify-content: center; text-align: center; }
  .admin-header .brand { justify-content: center; text-align: center; margin: 0 auto; }
  .admin-header .brand-text { text-align: center; }
  .admin-layout { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .admin-filter-bar { grid-template-columns: 1fr; }
  .bulk-save-bar { align-items: stretch; flex-direction: column; }
  .bulk-save-actions { width: 100%; }
  .bulk-save-actions .btn,
  .bulk-save-footer .btn { width: 100%; }

  .admin-table,
  .admin-table thead,
  .admin-table tbody,
  .admin-table th,
  .admin-table td,
  .admin-table tr { display: block; }
  .admin-table thead { display: none; }
  .admin-table tr {
    padding: 14px;
    margin-bottom: 12px;
    border: 1px solid var(--soft-border);
    border-radius: 18px;
    background: #fff;
  }
  .admin-table td {
    border: 0;
    padding: 8px 0;
    display: grid;
    grid-template-columns: 95px 1fr;
    gap: 12px;
    align-items: center;
  }
  .admin-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 800;
  }
  .admin-table input,
  .admin-table select { min-width: 0; }
  .admin-save-dock { align-items: stretch; flex-direction: column; text-align: center; }
  .admin-save-dock div { justify-content: center; width: 100%; }
  .admin-save-dock .btn { flex: 1; }
}

/* Print */
@media print {
  @page { size: A4; margin: 12mm; }
  html, body { background: #fff !important; }
  .no-print, .categories, .whatsapp-col, .whatsapp-btn { display: none !important; }
  .site-header { position: static; padding: 0 0 12px; margin-bottom: 14px; border-bottom: 1px solid #d0d5dd; box-shadow: none; }
  .brand { flex-direction: row; }
  .brand-logo { width: 160px; max-height: 64px; padding: 0; }
  .container { width: 100%; margin: 0; }
  .card { box-shadow: none; border-radius: 0; border: 0; }
  .table-head { padding: 8px 0 10px; }
  .table-wrapper { overflow: visible; }
  table, thead, tbody, th, td, tr { display: revert !important; }
  table { font-size: 11px; page-break-inside: auto; }
  thead { display: table-header-group !important; }
  tr { page-break-inside: avoid; page-break-after: auto; }
  th, td { padding: 7px 8px; border-bottom: 1px solid #e4e7ec; }
  th { background: #f5f5f5 !important; color: #111; }
  td::before { content: none !important; }
  .price { color: #111; font-weight: 800; }
}

.admin-stats {
  display: grid;
  gap: 10px;
  margin-bottom: 22px;
}
.admin-stats div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--soft-border);
  border-radius: 16px;
  background: #fbfcfd;
}
.admin-stats strong { color: var(--blue); font-size: 18px; }
.admin-stats span { color: var(--muted); font-weight: 700; }

/* Editable admin product fields */
.admin-table input[type="text"],
.admin-table input:not([type]),
.admin-table input[type="number"],
.admin-table select {
  width: 100%;
  box-sizing: border-box;
}
.admin-table .name-input,
.admin-table .package-input {
  min-width: 190px;
}
.admin-table .category-input {
  min-width: 170px;
}
.admin-table .item-no-input {
  min-width: 78px;
}
@media (max-width: 900px) {
  .admin-table .name-input,
  .admin-table .package-input,
  .admin-table .category-input,
  .admin-table .item-no-input {
    min-width: 0;
  }
}
