/*============================================================
  HESHAM WEB V7 — SAFE RESPONSIVE / BUSINESS-FLOW POLISH
  Loaded last. These rules intentionally refine, not redesign,
  the existing desktop and mobile UI.
============================================================*/

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

main,
section,
article,
.container,
.his-pro-inner,
.his-pro-nav,
.his-pro-actions,
.checkout-layout,
.checkout-shell,
.order-card,
.order-detail-grid {
  min-width: 0;
}

img,
video,
canvas,
svg {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(8,120,238,.28);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* Shared header: logo remains at the far left; navigation/actions stay right. */
.his-pro-brand {
  margin-right: 0;
}

.his-pro-nav {
  margin-left: auto;
}

.his-pro-actions {
  justify-content: flex-end;
}

.his-product-live-cart {
  flex: 0 0 auto;
}

/* Checkout and order lifecycle clarity. */
.checkout-review-rule,
.payment-rule-note,
.track-payment-rule,
.admin-order-rule {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  line-height: 1.55;
}

.checkout-review-rule,
.payment-rule-note.pending,
.track-payment-rule.pending,
.admin-order-rule.pending {
  color: #774a00;
  background: #fff8e7;
  border: 1px solid #f0d89e;
}

.payment-rule-note.paid,
.track-payment-rule.paid,
.admin-order-rule.paid {
  color: #096337;
  background: #eefaf3;
  border: 1px solid #bfe8d0;
}

.payment-rule-note strong,
.payment-rule-note p,
.track-payment-rule strong,
.track-payment-rule span {
  display: block;
}

.payment-rule-note p {
  margin: 5px 0 0;
}

.checkout-error-notice,
.track-error {
  background: #fff3f3 !important;
  border-color: #ffd0d0 !important;
  color: #9f1d1d !important;
}

/* Customer order actions. */
.order-actions,
.order-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.order-action.danger,
.order-modal-button.danger {
  color: #a92525;
  border-color: #efc4c4;
  background: #fff7f7;
}

.order-action.danger:hover,
.order-modal-button.danger:hover {
  color: #fff;
  border-color: #b72e2e;
  background: #b72e2e;
}

/* Secure order tracking form/result. */
.track-card {
  overflow: hidden;
}

.track-form {
  display: grid;
  grid-template-columns: minmax(190px,1fr) minmax(220px,1.15fr) auto;
  gap: 12px;
  align-items: end;
}

.track-form label {
  min-width: 0;
}

.track-form label > span {
  display: block;
  margin: 0 0 7px;
  color: #29445f;
  font-size: 12px;
  font-weight: 850;
}

.track-form input {
  width: 100%;
}

.track-form .btn {
  min-height: 46px;
  white-space: nowrap;
}

.track-privacy-note {
  margin: 11px 0 0;
  color: #6a7e92;
  font-size: 12px;
  line-height: 1.55;
}

.track-result-card {
  margin-top: 22px;
  border: 1px solid #dfe8f1;
  border-radius: 18px;
  padding: clamp(16px,3vw,25px);
  background: #fff;
}

.track-result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.track-result-head small,
.track-meta-grid small {
  display: block;
  color: #708297;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .08em;
}

.track-result-head h2 {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.track-status {
  display: inline-flex;
  align-items: center;
  min-height: 31px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #edf5ff;
  color: #0769cc;
  font-size: 11px;
  font-weight: 900;
  text-align: center;
}

.track-status.cancelled {
  background: #fff0f0;
  color: #a82424;
}

.track-meta-grid {
  display: grid;
  grid-template-columns: repeat(4,minmax(0,1fr));
  gap: 10px;
  margin-top: 18px;
}

.track-meta-grid p {
  min-width: 0;
  margin: 0;
  padding: 12px;
  border: 1px solid #e5edf5;
  border-radius: 12px;
  background: #f9fbfd;
}

.track-meta-grid strong {
  display: block;
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.track-payment-rule {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.track-shipping {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid #e1e9f2;
  border-radius: 12px;
  background: #f8fbfe;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.cancelled-timeline .order-step.cancelled i {
  background: #b72e2e;
  color: #fff;
}

/* Admin lifecycle state. */
.admin-order-rule {
  font-size: 12px;
  font-weight: 750;
}

#adminOrderStatus option:disabled {
  color: #9ba8b5;
}

#saveOrderStatus:disabled,
#markPaymentPaidButton:disabled,
#cancelOrderButton:disabled {
  cursor: not-allowed;
  opacity: .58;
}

/* Database-backed website assistant. */
.chat-launch[aria-expanded="true"] {
  transform: rotate(12deg) scale(.95);
}

.chat-panel {
  width: min(410px,calc(100vw - 32px));
  height: min(590px,calc(100dvh - 132px));
  min-height: 420px;
  max-height: 72vh;
}

.chat-head {
  flex: 0 0 auto;
}

.chat-head small {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-online-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b7df00;
  box-shadow: 0 0 0 3px rgba(183,223,0,.18);
}

.chat-head button,
.chat-form button,
.chat-suggestion-row button {
  cursor: pointer;
}

.chat-body {
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.bot-msg,
.user-msg {
  width: fit-content;
  max-width: 91%;
  overflow-wrap: anywhere;
  white-space: normal;
}

.user-msg {
  margin-left: auto;
  color: #fff;
  background: linear-gradient(135deg,#0878ee,#0058c8);
  border-bottom-right-radius: 5px;
}

.bot-msg {
  margin-right: auto;
  color: #17304a;
  border-bottom-left-radius: 5px;
}

.chat-message-copy {
  white-space: pre-line;
}

.chat-product-list {
  display: grid;
  gap: 7px;
  margin-top: 11px;
}

.chat-product-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #dfe9f3;
  border-radius: 10px;
  color: #143450;
  background: #f8fbff;
  transition: border-color .18s,background .18s;
}

.chat-product-card:hover {
  border-color: #9dcdf8;
  background: #eef7ff;
}

.chat-product-card span {
  min-width: 0;
}

.chat-product-card strong,
.chat-product-card small {
  display: block;
}

.chat-product-card strong {
  font-size: 12px;
  overflow-wrap: anywhere;
}

.chat-product-card small {
  margin-top: 3px;
  color: #677c91;
  font-size: 10px;
  line-height: 1.35;
}

.chat-product-card > b {
  flex: 0 0 auto;
  color: #0878ee;
  font-size: 21px;
}

.chat-link-row,
.chat-suggestion-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
}

.chat-link-row a,
.chat-suggestion-row button {
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid #cfe0f0;
  border-radius: 999px;
  color: #096acb;
  background: #fff;
  font-size: 10px;
  font-weight: 850;
  line-height: 1.2;
}

.chat-link-row a:hover,
.chat-suggestion-row button:hover {
  color: #fff;
  border-color: #0878ee;
  background: #0878ee;
}

.chat-suggestion-row--welcome {
  margin: 0 0 12px;
}

.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 54px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7890a7;
  animation: chatDot 1s infinite ease-in-out;
}

.chat-typing span:nth-child(2) { animation-delay: .14s; }
.chat-typing span:nth-child(3) { animation-delay: .28s; }

@keyframes chatDot {
  0%,60%,100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-form {
  flex: 0 0 auto;
  background: #fff;
}

.chat-form input {
  min-width: 0;
}

.chat-form.busy input,
.chat-form.busy button {
  opacity: .65;
  pointer-events: none;
}

/* Long values should wrap instead of pushing cards outside the viewport. */
.order-id,
.order-meta,
.order-detail-box,
.order-item-name,
.admin-detail-card,
.checkout-card,
.co-card {
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .track-form {
    grid-template-columns: 1fr 1fr;
  }

  .track-form .btn {
    grid-column: 1 / -1;
    width: 100%;
  }

  .track-meta-grid {
    grid-template-columns: repeat(2,minmax(0,1fr));
  }
}

@media (max-width: 700px) {
  .container,
  .his-pro-inner {
    width: min(100% - 24px,1180px);
  }

  .track-form,
  .track-meta-grid {
    grid-template-columns: 1fr;
  }

  .track-form .btn {
    grid-column: auto;
  }

  .track-result-head {
    align-items: stretch;
    flex-direction: column;
  }

  .track-status {
    align-self: flex-start;
  }

  .order-actions > *,
  .order-modal-actions > * {
    flex: 1 1 100%;
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .chat-panel {
    left: 12px;
    right: 12px;
    bottom: calc(82px + env(safe-area-inset-bottom));
    width: auto;
    height: min(620px,calc(100dvh - 106px - env(safe-area-inset-bottom)));
    max-height: none;
    min-height: 360px;
    border-radius: 17px;
  }

  .chat-launch {
    right: 14px;
    bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .whatsapp {
    right: 82px;
    bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .chat-body {
    padding: 13px;
  }

  .bot-msg,
  .user-msg {
    max-width: 94%;
    font-size: 13px;
  }
}

@media (max-width: 420px) {
  .his-pro-inner {
    width: calc(100% - 18px);
  }

  .chat-panel {
    left: 8px;
    right: 8px;
  }

  .chat-form {
    padding: 9px;
  }

  .chat-form input {
    padding: 11px;
  }
}

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