/* ==========================================================================
   Dedicated Mobile Web App Theme (<= 991px)
   Loaded via media="(max-width: 991px)" — zero desktop render-blocking cost!
   Native App Header + 5-Tab Bottom Bar + Horizontal Swipe Pills + Bottom Sheets
   ========================================================================== */

html, body {
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}

/* 1. Compact Native Mobile Topbar */
.td-topbar {
  height: 56px;
  padding: 0 10px;
  gap: 6px;
}
.td-top-left {
  flex: 1;
  min-width: 0;
  gap: 6px;
}
.td-top-right {
  gap: 5px;
  flex-shrink: 0;
}
.td-mobile-brand {
  display: inline-flex !important;
  flex: 1;
  min-width: 0;
  gap: 6px;
  font-size: 15px;
}
.td-mobile-brand img {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}
.td-mobile-brand span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.td-icon-btn {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}
.td-cmd-trigger {
  min-width: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  justify-content: center;
  flex-shrink: 0;
}
.td-cmd-text, .td-cmd-kbd {
  display: none !important;
}
.td-btn {
  white-space: normal;
  text-align: center;
  max-width: 100%;
  line-height: 1.3;
  padding: 8px 14px;
}
.td-btn-sm {
  padding: 6px 12px;
}
.td-top-right .td-btn-sm {
  white-space: nowrap;
  min-height: 34px;
  padding: 0 10px;
  font-size: 11.5px;
  max-width: 126px;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 420px) {
  .td-hide-xs { display: none !important; }
}

/* 2. Smooth Slide-Out Mobile Drawer */
.td-sidebar {
  width: min(304px, 85vw);
  border-radius: 0 24px 24px 0;
  box-shadow: 0 20px 56px rgba(15, 23, 42, 0.34);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.td-brand-head {
  justify-content: flex-start;
  padding-right: 52px;
  position: relative;
}
.td-side-close {
  display: inline-flex !important;
  position: absolute;
  top: 14px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--td-border);
  background: var(--td-surface-muted);
  color: var(--td-ink);
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
.td-nav-link {
  min-height: 44px;
  padding: 10px 12px;
  font-size: 14px;
}

/* 3. Native-App 5-Tab Bottom Navigation Bar with Raised Center FAB */
.td-bottom-nav {
  display: flex !important;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 34;
  height: calc(64px + env(safe-area-inset-bottom, 0px));
  padding: 4px 6px calc(6px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--td-border);
  box-shadow: 0 -10px 28px -12px rgba(15, 23, 42, 0.16);
  align-items: flex-end;
  justify-content: space-around;
}
[data-theme="dark"] .td-bottom-nav {
  background: rgba(20, 24, 33, 0.95);
  box-shadow: 0 -10px 28px -12px rgba(0, 0, 0, 0.55);
}
.td-bnav-item {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 50px;
  min-width: 0;
  padding: 2px 4px;
  border: none;
  background: transparent;
  color: var(--td-ink-muted);
  font-size: 10.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s, transform 0.12s;
}
.td-bnav-item:hover {
  text-decoration: none;
}
.td-bnav-item:active {
  transform: scale(0.94);
}
.td-bnav-item svg {
  width: 21px;
  height: 21px;
  stroke-width: 1.9;
  flex-shrink: 0;
}
.td-bnav-item.is-active {
  color: var(--td-brand-link);
}
.td-bnav-item.is-active::after {
  content: '';
  position: absolute;
  top: 0;
  width: 22px;
  height: 3px;
  border-radius: 999px;
  background: var(--td-brand-bright);
}
.td-bnav-dot {
  position: absolute;
  top: 4px;
  right: calc(50% - 17px);
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 9.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.td-bnav-fab {
  flex: 0 0 auto;
  width: 58px;
  height: 52px;
  margin: 0 2px 4px;
  padding: 0;
  border-radius: 18px;
  background: linear-gradient(135deg, #166d58 0%, #1e856c 100%);
  color: #ffffff !important;
  box-shadow: 0 10px 22px -6px rgba(22, 109, 88, 0.58);
  flex-direction: column;
  gap: 1px;
  font-size: 10px;
  font-weight: 700;
}
.td-bnav-fab svg {
  width: 20px;
  height: 20px;
  stroke-width: 2.3;
}
.td-bnav-fab::after {
  display: none !important;
}

/* 4. Content Spacing & Footer Clearance Above Bottom Nav */
.td-content {
  padding: 14px 12px 28px;
}
.td-footer {
  padding: 18px 14px calc(86px + env(safe-area-inset-bottom, 0px));
  font-size: 12.5px;
}
.td-ft-tabs {
  width: 100%;
  overflow-x: auto;
  flex-wrap: nowrap;
  scrollbar-width: none;
}
.td-ft-tabs::-webkit-scrollbar { display: none; }
.td-ft-tab { flex: 1 0 auto; white-space: nowrap; font-size: 12.5px; padding: 6px 10px; }
.td-ft-cgrid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }
@media (max-width: 520px) { .td-ft-cgrid { grid-template-columns: minmax(0, 1fr) !important; } }
.td-footer-links {
  gap: 8px 12px;
}
.td-breadcrumb {
  font-size: 11.5px;
  margin-bottom: 6px;
}
.td-page-head {
  gap: 10px;
  margin-bottom: 14px;
  align-items: flex-start;
}
.td-page-title {
  font-size: 21px;
  line-height: 1.24;
}
.td-page-sub {
  font-size: 13px;
  line-height: 1.5;
}
.td-head-actions {
  width: 100%;
  gap: 8px;
}
.td-head-actions > .td-btn {
  flex: 1 1 auto;
  min-height: 38px;
  padding: 0 12px;
  font-size: 12.5px;
}

/* 5. Prevent Grid Span Overflow on Mobile & Tablet */
.td-form-grid > .td-col-span-2,
.td-ps-filters > .td-col-span-2 {
  grid-column: auto !important;
}
@media (max-width: 768px) {
  .td-form-grid,
  .td-ps-filters {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .td-form-grid > *,
  .td-ps-filters > * {
    grid-column: auto !important;
  }
}

/* 6. Prevent iOS Safari Auto-Zoom on Focus */
.td-input,
.td-select,
.td-textarea,
.td-conv-bar input {
  font-size: 16px;
}

/* 7. Horizontal Touch-Swipe Navigation Strips (No Cramped Multi-Row Wraps!) */
.td-hub-tabs,
.td-ord-tabs,
.td-scroll-pills {
  flex-wrap: nowrap !important;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 6px;
}
.td-hub-tabs::-webkit-scrollbar,
.td-ord-tabs::-webkit-scrollbar,
.td-scroll-pills::-webkit-scrollbar,
.td-seg-tabs::-webkit-scrollbar,
.td-chip-row::-webkit-scrollbar {
  display: none;
}
.td-hub-tabs {
  gap: 6px;
  padding: 5px;
  margin-bottom: 14px;
  border-radius: 14px;
}
.td-hub-tab,
.td-ord-tab,
.td-scroll-pills > .td-btn {
  flex: 0 0 auto;
  white-space: nowrap;
}
.td-seg-tabs {
  display: flex;
  flex-wrap: nowrap;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.td-seg-btn {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 6px 11px;
  font-size: 12.5px;
}
.td-chip-row {
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.td-chip {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 6px 11px;
  font-size: 12px;
}
.td-deal-filter-group {
  flex-direction: column;
  gap: 6px;
}
.td-deal-flbl {
  min-width: 0;
  padding-top: 0;
  font-size: 12px;
}

/* 8. Home Hero, Converter Bar, KPI Strip & Shortcuts */
.td-card,
.td-hero-emerald,
.td-virtual-card {
  padding: 16px;
  border-radius: 18px;
}
.td-grid {
  gap: 14px;
}
.td-mt-20 {
  margin-top: 14px;
}
.td-conv-bar {
  flex-direction: column;
  align-items: stretch;
  padding: 8px;
  gap: 8px;
}
.td-conv-bar input {
  padding: 8px 10px;
}
.td-conv-btns {
  display: flex;
  width: 100%;
  gap: 8px;
}
.td-conv-btns .td-btn-primary {
  flex: 1;
}
.td-kpi-strip {
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
}
.td-kpi-item {
  border-right: none;
  padding-right: 0;
  gap: 9px;
}
.td-kpi-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 14px;
}
.td-kpi-val {
  font-size: 15px;
}
.td-kpi-lbl {
  font-size: 11px;
}
.td-grid-6 {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  gap: 8px;
}
.td-shortcut {
  padding: 12px 6px;
  border-radius: 14px;
  font-size: 12px;
  gap: 6px;
}

/* 9. Product Search & Deal 1K Mobile 2-Column Grid */
@media (max-width: 720px) {
  .td-prod-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
  }
  .td-prod-card {
    border-radius: 14px;
  }
  .td-prod-body {
    padding: 9px;
    gap: 6px;
  }
  .td-prod-title {
    font-size: 12.5px;
    min-height: 34px;
  }
  .td-prod-price {
    font-size: 15px;
  }
  .td-prod-orig {
    font-size: 11px;
  }
  .td-prod-pills .td-status {
    font-size: 10.5px;
    padding: 2px 7px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .td-prod-actions {
    flex-direction: column;
    gap: 5px;
  }
  .td-prod-actions .td-btn-sm {
    min-height: 34px;
    font-size: 12px;
    width: 100%;
    justify-content: center;
  }
  .td-ps-main {
    flex-direction: column;
  }
  .td-ps-main .td-input {
    min-width: 0;
    width: 100%;
  }
  .td-ps-main .td-btn {
    width: 100%;
  }
}

/* 10. Gift Store 2-Column Mobile Grid */
@media (max-width: 640px) {
  .td-gift-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
  }
  .td-gift-card {
    padding: 13px !important;
  }
  .td-gift-card h3 {
    font-size: 13.5px !important;
  }
  .td-gift-card .td-btn-sm {
    width: 100%;
    font-size: 11.5px;
    padding: 0 8px;
  }
}
@media (max-width: 360px) {
  .td-gift-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* 11. Voucher Cards Mobile Optimization */
@media (max-width: 640px) {
  .td-voucher-stub {
    width: 78px;
    padding: 10px 6px;
    font-size: 11.5px;
  }
  .td-voucher-body {
    padding: 11px 12px;
  }
  .td-voucher-title {
    font-size: 13.5px;
  }
}

/* 12. Order Tracking Cards Mobile Polish (/don-hang) */
@media (max-width: 720px) {
  .td-ord-sum {
    padding: 12px;
    gap: 10px;
    align-items: flex-start;
  }
  .td-ord-thumb {
    width: 52px;
    height: 52px;
    border-radius: 10px;
  }
  .td-ord-mid {
    min-width: 0;
    flex: 1 1 calc(100% - 66px);
  }
  .td-ord-title {
    font-size: 13.5px;
  }
  .td-ord-prog {
    max-width: none;
  }
  .td-ord-right {
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    border-top: 1px dashed var(--td-border);
    padding-top: 8px;
    margin-top: 2px;
  }
  .td-ord-cb-lbl {
    display: none;
  }
  .td-ord-cb-val {
    font-size: 16px;
  }
  .td-ord-detail {
    padding: 0 12px 12px;
  }
  .td-ord-actions .td-btn-sm {
    flex: 1 1 auto;
  }
}

/* 13. Ecosystem Cards -> Sleek Horizontal Swipe Carousel on Mobile (saves huge scroll height!) */
.td-eco-grid {
  display: flex !important;
  flex-wrap: nowrap;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  gap: 10px;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.td-eco-grid::-webkit-scrollbar {
  display: none;
}
.td-eco-grid .td-eco-card {
  flex: 0 0 210px;
  scroll-snap-align: start;
  padding: 13px;
}
@media (max-width: 640px) {
  .td-pseo-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px;
  }
  .td-pseo-grid .td-eco-card {
    padding: 12px;
  }
}

/* 14. Tables & Voucher Search: Clean Fit & Compact Cells */
.td-voucher-search-wrap {
  width: 100%;
  flex: 1 1 100%;
  min-width: 0 !important;
}
.td-table-wrap {
  -webkit-overflow-scrolling: touch;
}
.td-table {
  font-size: 12px;
}
.td-table th,
.td-table td {
  padding: 8px 8px;
}

/* 15. Native Bottom-Sheet Modals on Small Phones */
@media (max-width: 640px) {
  .td-modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .td-modal,
  .td-modal-sm {
    max-width: 100%;
    border-radius: 22px 22px 0 0;
    border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .td-modal-head::before {
    content: '';
    position: absolute;
    top: 7px;
    left: 50%;
    transform: translateX(-50%);
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: var(--td-border-strong);
  }
  .td-modal-head {
    position: relative;
    padding-top: 20px;
  }
  .td-modal-body {
    max-height: 74vh;
  }
  .td-toast-stack {
    top: auto;
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
    left: 10px;
    right: 10px;
    width: auto;
  }
}
