/* BHAMIRA PWA v29.16 — Messages + Order Leads + image send */

.module-hidden {
  display: none !important;
}

.module-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  margin: -2px 0 12px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255,255,255,0.92);
  box-shadow: 0 6px 18px rgba(59,7,7,0.05);
  position: sticky;
  top: 6px;
  z-index: 120;
}

.module-nav-btn {
  min-width: 0;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #5b4439;
  padding: 10px 8px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.module-nav-btn.active {
  background: var(--maroon);
  color: white;
  box-shadow: inset 0 0 0 1px var(--gold);
}

.module-nav-badge {
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  padding: 0 5px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  line-height: 1;
  background: #fff1db;
  color: var(--maroon);
  border: 1px solid #e7c687;
}

.module-nav-btn.active .module-nav-badge {
  background: #fff7e8;
  color: var(--maroon);
}

.module-nav-badge:empty,
.module-nav-badge[data-count="0"] {
  display: none;
}

.workspace-module {
  margin-bottom: 26px;
}

.workspace-head {
  background: white;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 13px 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.workspace-head h2 {
  margin: 0;
  font-size: 18px;
  color: var(--maroon);
}

.workspace-head p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.workspace-head-actions {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace-small-btn {
  border: 1px solid #dfc69b;
  border-radius: 11px;
  background: #fff7e8;
  color: var(--maroon);
  font-size: 12px;
  font-weight: 800;
  padding: 8px 10px;
  cursor: pointer;
  white-space: nowrap;
}

.workspace-small-btn.primary-action {
  background: var(--maroon);
  color: white;
  border-color: var(--gold);
}

.workspace-small-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.workspace-status {
  font-size: 11px;
  color: var(--muted);
  min-height: 15px;
}

.workspace-error {
  border: 1px solid #efb5ad;
  background: #fff2f0;
  color: #8f1d15;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 12px;
  margin-bottom: 9px;
}

/* ============================ MESSAGES ============================ */

.wa-shell {
  display: grid;
  grid-template-columns: minmax(230px, 0.9fr) minmax(0, 1.5fr);
  min-height: 590px;
  max-height: 72vh;
  background: white;
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(59,7,7,0.06);
}

.wa-sidebar {
  min-width: 0;
  border-right: 1px solid var(--border);
  background: #fffdf9;
  display: flex;
  flex-direction: column;
}

.wa-sidebar-head {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  background: #fff8ef;
}

.wa-search-wrap {
  position: relative;
}

.wa-search-wrap input {
  margin: 0;
  padding: 10px 12px 10px 34px;
  border-radius: 12px;
  font-size: 14px;
  background: white;
}

.wa-search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #8f7566;
  font-size: 14px;
  pointer-events: none;
}

.wa-filter-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.wa-filter-btn {
  border: 1px solid #e2cfaf;
  background: white;
  color: #644d42;
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.wa-filter-btn.active {
  background: #fff1db;
  color: var(--maroon);
  border-color: #d8b36c;
}

.wa-conversation-list {
  overflow-y: auto;
  flex: 1;
}

.wa-empty-list {
  padding: 24px 14px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.wa-conversation-card {
  border: 0;
  width: 100%;
  background: transparent;
  text-align: left;
  padding: 11px 12px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  cursor: pointer;
  border-bottom: 1px solid #f1e7d9;
}

.wa-conversation-card:hover,
.wa-conversation-card.active {
  background: #fff3df;
}

.wa-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  background: var(--maroon);
  color: #f8d98d;
  font-size: 14px;
  font-weight: 900;
  border: 1px solid var(--gold);
}

.wa-card-main {
  min-width: 0;
}

.wa-card-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 13px;
  font-weight: 800;
  color: #2e201b;
}

.wa-card-name span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wa-window-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #2f8f59;
  flex: 0 0 auto;
}

.wa-card-preview {
  margin-top: 3px;
  color: #6d5a50;
  font-size: 11px;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wa-card-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  color: #8b7569;
  font-size: 9px;
  white-space: nowrap;
}

.wa-unread {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  box-sizing: border-box;
  border-radius: 999px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  background: #2f8f59;
  color: white;
  font-size: 10px;
  font-weight: 900;
}

.wa-chat-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #f6efe5;
  position: relative;
}

.wa-chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px;
  color: #6c5a50;
}

.wa-chat-empty strong {
  display: block;
  color: var(--maroon);
  margin-bottom: 5px;
}

.wa-chat-head {
  min-height: 58px;
  box-sizing: border-box;
  padding: 9px 11px;
  background: #fff8ef;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 9px;
}

.wa-chat-head-main {
  min-width: 0;
  flex: 1;
}

.wa-chat-name {
  font-size: 14px;
  font-weight: 900;
  color: #2c1c18;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wa-chat-sub {
  margin-top: 2px;
  font-size: 10px;
  color: #7f695e;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wa-back-btn {
  display: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #e1cda9;
  background: white;
  color: var(--maroon);
  font-size: 18px;
  cursor: pointer;
}

.wa-chat-actions {
  display: flex;
  gap: 6px;
}

.wa-message-list {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.wa-message-row {
  display: flex;
}

.wa-message-row.out {
  justify-content: flex-end;
}

.wa-message-row.in {
  justify-content: flex-start;
}

.wa-bubble {
  max-width: min(78%, 510px);
  border-radius: 13px;
  padding: 8px 10px 6px;
  box-shadow: 0 1px 3px rgba(59,7,7,0.08);
  border: 1px solid rgba(84,55,40,0.08);
  background: white;
  color: #271b17;
  font-size: 13px;
  line-height: 1.35;
  word-break: break-word;
}

.wa-message-row.out .wa-bubble {
  background: #fff0c9;
  border-color: #e6c77b;
}

.wa-message-text {
  white-space: pre-wrap;
}

.wa-media-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
  padding: 7px 9px;
  border-radius: 9px;
  background: rgba(255,255,255,0.72);
  border: 1px solid #ddcba8;
  color: var(--maroon);
  text-decoration: none;
  font-size: 11px;
  font-weight: 800;
}

.wa-message-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  margin-top: 4px;
  color: #847267;
  font-size: 9px;
}

.wa-status-read {
  color: #1e8651;
  font-weight: 900;
}

.wa-day-divider {
  align-self: center;
  background: rgba(255,255,255,0.86);
  border: 1px solid #e4d3ba;
  border-radius: 999px;
  padding: 4px 9px;
  color: #735f53;
  font-size: 9px;
  font-weight: 800;
  margin: 5px 0;
}

.wa-composer {
  background: #fff8ef;
  border-top: 1px solid var(--border);
  padding: 9px;
}

.wa-window-note {
  margin-bottom: 6px;
  font-size: 10px;
  line-height: 1.3;
  color: #705f55;
}

.wa-window-note.closed {
  color: #a1261e;
}

.wa-compose-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  align-items: end;
}

.wa-compose-row textarea {
  width: 100%;
  min-height: 43px;
  max-height: 110px;
  resize: vertical;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: white;
  padding: 10px 11px;
  font: inherit;
  font-size: 14px;
  outline: none;
}

.wa-send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--gold);
  background: var(--maroon);
  color: white;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
}

.wa-send-btn:disabled,
.wa-compose-row textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================ ORDERS ============================ */

.order-toolbar {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.order-filter-btn {
  border: 1px solid #dfc9a5;
  background: white;
  color: #684f43;
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.order-filter-btn.active {
  background: #fff0d0;
  color: var(--maroon);
  border-color: #d1a84f;
}

.order-create-panel {
  background: white;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 13px;
  margin-bottom: 10px;
  box-shadow: 0 8px 20px rgba(59,7,7,0.05);
}

.order-create-panel h3 {
  margin: 0 0 10px;
  color: var(--maroon);
  font-size: 16px;
}

.order-form-grid {
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  gap: 9px;
}

.order-create-panel label {
  font-size: 12px;
}

.order-create-panel input,
.order-create-panel textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: white;
  padding: 10px 11px;
  font: inherit;
  font-size: 14px;
  margin-bottom: 9px;
}

.order-create-panel textarea {
  min-height: 94px;
  resize: vertical;
}

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

.order-form-actions .workspace-small-btn {
  min-width: 92px;
}

.order-board-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 10px;
}

.order-stat {
  background: white;
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 9px;
  text-align: center;
}

.order-stat strong {
  display: block;
  color: var(--maroon);
  font-size: 17px;
}

.order-stat span {
  font-size: 9px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.order-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.order-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  box-shadow: 0 7px 18px rgba(59,7,7,0.05);
  min-width: 0;
}

.order-card.closed-card {
  opacity: 0.86;
}

.order-card-head {
  display: flex;
  justify-content: space-between;
  gap: 9px;
  align-items: flex-start;
}

.order-person {
  min-width: 0;
}

.order-person strong {
  display: block;
  font-size: 14px;
  color: #2b1c18;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-person span {
  display: block;
  margin-top: 2px;
  color: #7a665a;
  font-size: 10px;
}

.order-status-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 8px;
  font-size: 9px;
  font-weight: 900;
  letter-spacing: 0.2px;
  background: #fff0d0;
  color: #714b00;
  border: 1px solid #e6c579;
}

.order-status-pill.done {
  background: #edf8f1;
  color: #14663b;
  border-color: #a8d7ba;
}

.order-status-pill.not-possible {
  background: #fff1ef;
  color: #8d261d;
  border-color: #efbab3;
}

.order-status-pill.cancelled {
  background: #f3f1ef;
  color: #685c55;
  border-color: #d8d0ca;
}

.order-text {
  margin: 10px 0;
  background: #fffaf3;
  border: 1px solid #f0e0c9;
  border-radius: 11px;
  padding: 9px;
  font-size: 12px;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 42px;
}

.order-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #8b766a;
  font-size: 9px;
  margin-bottom: 9px;
}

.order-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.order-action-btn {
  flex: 1 1 auto;
  border: 1px solid #dfcba9;
  border-radius: 10px;
  background: #fff9ef;
  color: var(--maroon);
  font-size: 10px;
  font-weight: 900;
  padding: 7px 8px;
  cursor: pointer;
}

.order-action-btn.done {
  background: #edf8f1;
  color: #14663b;
  border-color: #acd9bd;
}

.order-action-btn.not-possible {
  background: #fff4ef;
  color: #91291f;
  border-color: #efc1ba;
}

.order-action-btn.cancelled {
  background: #f3f1ef;
  color: #60544d;
  border-color: #d6cec8;
}

.order-empty {
  grid-column: 1 / -1;
  background: white;
  border: 1px dashed #dbc39b;
  border-radius: 16px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 760px) {
  .module-nav {
    top: 4px;
  }

  .workspace-head {
    align-items: flex-start;
  }

  .wa-shell {
    display: block;
    min-height: 66vh;
    max-height: none;
    height: calc(100vh - 215px);
  }

  .wa-sidebar,
  .wa-chat-panel {
    height: 100%;
  }

  .wa-sidebar {
    border-right: 0;
  }

  .wa-chat-panel {
    display: none;
  }

  .wa-shell.chat-open .wa-sidebar {
    display: none;
  }

  .wa-shell.chat-open .wa-chat-panel {
    display: flex;
  }

  .wa-back-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .wa-chat-actions .workspace-small-btn {
    font-size: 10px;
    padding: 7px 8px;
  }

  .order-grid {
    grid-template-columns: 1fr;
  }

  .order-board-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 460px) {
  .module-nav-btn {
    font-size: 12px;
    padding: 9px 5px;
  }

  .workspace-head {
    display: block;
  }

  .workspace-head-actions {
    justify-content: flex-start;
    margin-top: 9px;
  }

  .order-form-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .wa-bubble {
    max-width: 86%;
  }
}

.app.workspace-mode {
  max-width: 1180px;
  padding-bottom: 36px;
}


/* ============================ v29.15 SCROLL + DENSITY FIX ============================ */

/* Lists need an explicit shrink point before overflow-y can take effect. */
.wa-sidebar,
.wa-chat-panel,
#waChatContent,
.wa-conversation-list,
.wa-message-list {
  min-height: 0;
}

.wa-conversation-list,
.wa-message-list,
#itemsList,
.queue-list {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  scrollbar-gutter: stable;
}

.wa-image-preview-link {
  display: block;
  margin-top: 6px;
  border-radius: 11px;
  overflow: hidden;
  border: 1px solid #dcc8a4;
  background: #f2eadf;
  text-decoration: none;
  max-width: min(360px, 100%);
}

.wa-image-preview {
  display: block;
  width: 100%;
  max-height: 330px;
  object-fit: contain;
  background: #efe6da;
}

.wa-image-preview.preview-loading {
  min-width: 210px;
  min-height: 150px;
  background:
    linear-gradient(100deg, #eee4d7 30%, #f8f1e7 50%, #eee4d7 70%);
  background-size: 300% 100%;
  animation: bhamiraPreviewPulse 1.3s ease-in-out infinite;
}

.wa-image-preview.preview-failed {
  min-height: 92px;
  object-fit: none;
  background: #f7f1e8;
}

@keyframes bhamiraPreviewPulse {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

/* Compact the Billing / Messages / Orders row. */
.module-nav {
  padding: 3px;
  gap: 4px;
  margin-bottom: 7px;
  border-radius: 12px;
}

.module-nav-btn {
  padding: 6px 7px;
  min-height: 29px;
  border-radius: 9px;
  font-size: 12px;
}

.module-nav-badge {
  min-width: 16px;
  height: 16px;
  font-size: 9px;
}

.workspace-head {
  padding: 9px 11px;
  border-radius: 14px;
  margin-bottom: 7px;
}

.workspace-head h2 { font-size: 16px; }
.workspace-head p { margin-top: 2px; font-size: 11px; }

/* A real height lets both WhatsApp panes scroll independently. */
.wa-shell {
  height: min(72dvh, 720px);
  min-height: 460px;
  max-height: none;
}

/* Make completed queue records reachable instead of being clipped below the desktop viewport. */
.queue-list {
  overflow-y: auto !important;
  max-height: min(60dvh, 520px) !important;
}

@media (min-width: 1100px) {
  /* Previous POS desktop mode locked the entire document with overflow:hidden.
     That works for three fixed billing columns but prevents Orders/Messages and
     long billing content from scrolling. Keep the compact POS layout, but allow
     the document and its dedicated scroll panes to move. */
  html,
  body {
    height: auto !important;
    min-height: 100% !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
  }

  .app {
    height: auto !important;
    min-height: calc(100dvh - 50px) !important;
    overflow: visible !important;
  }

  .module-nav {
    width: min(100%, 470px);
    margin-left: auto;
    margin-right: auto;
    top: 4px;
  }

  #itemsList {
    overflow-y: auto !important;
    min-height: 0 !important;
    max-height: 100% !important;
  }

  .queue-list {
    height: auto !important;
    max-height: min(60dvh, 520px) !important;
  }

  #ordersModule {
    overflow: visible;
  }
}

@media (max-width: 760px) {
  .wa-shell {
    height: calc(100dvh - 170px);
    min-height: 420px;
    max-height: calc(100dvh - 120px);
  }

  .module-nav-btn {
    padding: 6px 5px;
    min-height: 30px;
  }
}

/* v29.16 WhatsApp image composer */
.wa-compose-row { grid-template-columns: auto minmax(0,1fr) auto !important; }
.wa-attach-btn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--border);
  background: #fffaf3; color: var(--maroon); cursor: pointer; font-size: 19px;
  display: grid; place-items: center; flex: 0 0 auto;
}
.wa-attach-btn:disabled { opacity: .45; cursor: not-allowed; }
.wa-image-draft {
  display: grid; grid-template-columns: 58px minmax(0,1fr) 32px; align-items: center; gap: 9px;
  padding: 8px; margin: 0 0 7px; border: 1px solid var(--border); border-radius: 12px; background: #fffaf3;
}
.wa-image-draft img { width: 58px; height: 58px; object-fit: cover; border-radius: 9px; background: #eee; }
.wa-image-draft-meta { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.wa-image-draft-meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.wa-image-draft-meta span { color: var(--muted); font-size: 11px; }
.wa-image-remove-btn { border: 0; background: transparent; color: var(--danger); font-size: 24px; cursor: pointer; }


/* V29.17 locally protected order cards */
.order-card:has(.order-status-pill) .order-status-pill { white-space: nowrap; }
.order-status-pill:not(.done):not(.not-possible):not(.cancelled) { max-width: 140px; }
