/* Base */
.tptm {
  direction: rtl;
  font-family: "IBM Plex Sans Hebrew", inherit;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Reset any conflicting table styles */
.tptm table,
.tptm table * {
  box-sizing: border-box !important;
}

.tptm table {
  border-collapse: separate !important;
  border-spacing: 0 !important;
}

.tptm table td,
.tptm table th {
  border: none !important;
  margin: 0 !important;
  padding: 0 !important;
}
.tptm h2, .tptm h3 { margin: .4rem 0; }
.tptm .tptm-error { background:#fff4f4; border:1px solid #f2c0c0; padding:12px; border-radius:8px; color:#a33; }
.tptm .tptm-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; }

/* Product list */
.tptm .tptm-product-list {
  display:grid; grid-template-columns: repeat(auto-fill, minmax(32%,1fr));
  gap:12px; margin:8px 0 14px;
}
.tptm .tptm-product {
  display:flex; gap:10px; align-items:center; width:100%;
  border:1px solid #e6e6e6; padding:10px; border-radius:12px; background:#fff; cursor:pointer;
  transition:box-shadow .2s, transform .05s;
  max-width:100%;
  color:#1b2d5b;
  white-space:wrap;
}
.tptm .tptm-product:hover {color:#1b2d5b; box-shadow: 0 3px 14px rgba(0,0,0,.06); }
.tptm .tptm-product:active { transform: translateY(1px);color:#1b2d5b }
.tptm .tptm-product-thumb { width:48px; height:48px; border-radius:8px; overflow:hidden; background:#f3f3f3; flex:0 0 48px; }
.tptm .tptm-product-thumb img { width:100%; height:100%; object-fit:cover; display:block; }
.tptm .tptm-product-meta { display:flex; flex-direction:column; min-width:0; }
.tptm .tptm-product-name {
  font-weight:600; max-width:100%;text-align:right;
}
.tptm .tptm-product-sku { font-size:.85rem; color:#666;}

.tptm .tptm-confirm {display: block !important;
  padding: 5px 20px !important;
  min-height: auto !important;
  border-radius: 50px !important;margin:0 auto;}


/* Buttons */
.tptm .tptm-tools { margin:10px 0 18px;text-align:center }
#tptm-scan {background:#121f41;color:#fff;border:0;border-radius:50px;font-weight:700;padding:7px 25px;}
.tptm .tptm-btn { 
  border:1px solid #e0e0e0; 
  background:#fff; 
  padding:8px 12px; 
  border-radius:10px; 
  cursor:pointer; 
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px; /* Touch-friendly minimum size */
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tptm .tptm-btn-primary { background:#1f6feb; color:#fff; border-color:#1f6feb; }
.tptm .tptm-btn-secondary { background:#f5f7fb; }
.tptm .tptm-btn:disabled { opacity:.5; cursor:not-allowed; }
.tptm .tptm-busy { opacity:.8; }

/* Panel & stats */
.tptm .tptm-product-panel { border-top:1px solid #eee; padding-top:12px; }
.tptm .tptm-hidden { display:none; }

.tptm .tptm-panel-header { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-wrap:wrap; }
.tptm .tptm-selected-product { font-size:1.05rem; font-weight:700; }
.tptm .tptm-stats { display:flex; gap:18px; flex-wrap:wrap; }
.tptm .tptm-stats div { background:#fafafa; border:1px solid #eee; padding:8px 10px; border-radius:10px; }

/* Filters */
.tptm .tptm-filters { margin:12px 0; }
.tptm #tptm-search { width:100%; padding:10px 12px; border:1px solid #ddd; border-radius:10px; }

/* Table */
.tptm .tptm-table-wrap { 
  position: relative; 
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tptm .tptm-table { 
  width: 100% !important; 
  border-collapse: separate !important; 
  border-spacing: 0 !important; 
  border: 1px solid #eee !important; 
  border-radius: 12px !important; 
  overflow: hidden !important; 
  background: #fff !important;
  font-size: 14px !important;
  table-layout: auto !important;
}

.tptm .tptm-table thead th { 
  background: #f8f9fb !important; 
  text-align: right !important; 
  font-weight: 700 !important; 
  padding: 12px 10px !important; 
  border-bottom: 1px solid #eee !important;
  font-size: 13px !important;
  white-space: nowrap !important;
}

.tptm .tptm-table tbody td { 
  padding: 10px !important; 
  border-bottom: 1px solid #f2f2f2 !important; 
  vertical-align: middle !important;
  font-size: 13px !important;
}

.tptm .tptm-table tbody tr:last-child td { 
  border-bottom: none !important; 
}

.tptm .tptm-table tbody tr:hover {
  background-color: #f8f9fb !important;
}

.tptm .tptm-table tbody tr:nth-child(even) {
  background-color: #fafafa !important;
}

.tptm .tptm-table tbody tr:nth-child(even):hover {
  background-color: #f0f0f0 !important;
}

/* Override common WordPress theme table styles */
.tptm .tptm-table,
.tptm .tptm-table table,
.tptm .tptm-table thead,
.tptm .tptm-table tbody,
.tptm .tptm-table tfoot,
.tptm .tptm-table tr,
.tptm .tptm-table th,
.tptm .tptm-table td {
  border: none !important;
  margin: 0 !important;
  padding: 0 !important;
  background: transparent !important;
  font-size: inherit !important;
  line-height: inherit !important;
  color: inherit !important;
  text-align: inherit !important;
  vertical-align: inherit !important;
  font-weight: inherit !important;
  font-family: inherit !important;
}

/* Ensure our specific table styles take precedence */
.tptm .tptm-table {
  border: 1px solid #eee !important;
  border-radius: 12px !important;
  background: #fff !important;
}

.tptm .tptm-table thead th {
  background: #f8f9fb !important;
  padding: 12px 10px !important;
  border-bottom: 1px solid #eee !important;
  font-weight: 700 !important;
  text-align: right !important;
}

.tptm .tptm-table tbody td {
  padding: 10px !important;
  border-bottom: 1px solid #f2f2f2 !important;
  vertical-align: middle !important;
}

/* Mobile cards - hidden by default on desktop */
.tptm .tptm-mobile-cards {
  display: none;
}
.tptm select.tptm-qty-select { 
  padding:6px 8px; 
  border:1px solid #ddd; 
  border-radius:8px; 
  max-width:100%; 
  min-height: auto; /* Touch-friendly */
  font-size: 15px; /* Prevent zoom on iOS */
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6,9 12,15 18,9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: left 8px center;
  background-size: 16px;
  padding-left: 32px;
}

/* Pagination */
.tptm .tptm-pagination { display:flex; gap:12px; align-items:center; justify-content:flex-end; padding:10px 0; }

/* Loading overlay */
.tptm .tptm-loading { position:relative; }
.tptm .tptm-loading::after {
  content:''; position:absolute; inset:0; background:rgba(255,255,255,.6);
  backdrop-filter:saturate(120%) blur(2px);
}
.tptm .tptm-loading::before {
  content:''; position:absolute; top:50%; left:50%; width:24px; height:24px; margin:-12px 0 0 -12px;
  border-radius:50%; border:3px solid #ccc; border-top-color:#1f6feb; animation:tptm-spin .9s linear infinite;
}
@keyframes tptm-spin { to { transform:rotate(360deg); } }

/* Toast */
.tptm .tptm-toast {
  position:fixed; right:16px; bottom:16px; background:#1f6feb; color:#fff; padding:10px 14px;
  border-radius:10px; opacity:0; transform:translateY(6px); transition: all .2s; z-index:99999;
}
.tptm .tptm-toast.err { background:#d33; }
.tptm .tptm-toast.show { opacity:1; transform:translateY(0); }

/* Modal (closed by default) */
#tptm-qr-modal { display:none; }
#tptm-qr-modal.is-open { display:flex; }
#tptm-qr-modal {
  position:fixed; inset:0; background:rgba(0,0,0,.4);
  align-items:center; justify-content:center; z-index:9999;
}
.tptm .tptm-modal-content { width:min(720px, 96vw); background:#fff; border-radius:12px; overflow:hidden; }
.tptm .tptm-modal-header { display:flex; align-items:center; justify-content:space-between; padding:10px 14px; background:#f8f9fb; }
.tptm .tptm-modal-body { padding:14px; }
.tptm .tptm-modal-close { background:transparent; border:none; font-size:22px; line-height:1; cursor:pointer; }
.tptm .tptm-note { color:#666; font-size:.9rem; }

/* QR Scanner */
#tptm-qr-target { 
  min-height: 300px; 
  display: flex; 
  align-items: center; 
  justify-content: center; 
  background: #f8f9fb; 
  border-radius: 8px; 
  margin-bottom: 10px;
}
#tptm-qr-target canvas { border-radius: 8px; }

/* Order Info Display */
.tptm .tptm-order-info {
  background: #f8f9fb; 
  border: 1px solid #e6e6e6; 
  border-radius: 12px; 
  padding: 16px; 
  margin-bottom: 16px;
}
.tptm .tptm-order-info h4 { margin: 0 0 8px 0; color: #1f6feb; }
.tptm .tptm-order-info p { margin: 4px 0; font-size: 0.9rem; }

/* Order Items */
.tptm .tptm-order-item {
  background: #fff; 
  border: 1px solid #e6e6e6; 
  border-radius: 12px; 
  padding: 16px; 
  margin-bottom: 12px;
  transition: box-shadow 0.2s;
}
.tptm .tptm-order-item:hover { box-shadow: 0 3px 14px rgba(0,0,0,.06); }

.tptm .tptm-item-header h5 { 
  margin: 0 0 12px 0; 
  color: #333; 
  font-size: 1.1rem; 
  font-weight: 600;
}

.tptm .tptm-item-stats {
  display: flex; 
  gap: 16px; 
  margin-bottom: 16px; 
  flex-wrap: wrap;
}
.tptm .tptm-item-stats div {
  background: #fafafa; 
  border: 1px solid #eee; 
  padding: 8px 12px; 
  border-radius: 8px; 
  font-size: 0.9rem;
}

.tptm .tptm-item-controls {
  display: flex; 
  align-items: center; 
  gap: 12px; 
  flex-wrap: wrap;
}
.tptm .tptm-item-controls label {
  font-weight: 600; 
  color: #333; 
  margin: 0;
}
.tptm .tptm-item-controls .tptm-qty-select {
  padding: 6px 8px; 
  border: 1px solid #ddd; 
  border-radius: 6px; 
  min-width: 80px;
}
.tptm .tptm-item-controls .tptm-update-item {
  padding: 8px 16px; 
  font-size: 0.9rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  /* Product grid responsive */
  .tptm .tptm-product-list {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  
  /* Product cards mobile */
  .tptm .tptm-product {
    padding: 8px;
    gap: 8px;
  }
  
  .tptm .tptm-product-thumb {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
  }
  
  .tptm .tptm-product-name {
    font-size: 0.9rem;
  }
  
  .tptm .tptm-product-sku {
    font-size: 0.8rem;
  }
  
  /* Header responsive */
  .tptm .tptm-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .tptm .tptm-panel-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .tptm .tptm-stats {
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }
  
  .tptm .tptm-stats div {
    width: 100%;
    text-align: center;
  }
  
  /* Hide table on mobile and show card layout */
  .tptm .tptm-table-wrap {
    display: none;
  }
  
  /* Mobile card layout for table data */
  .tptm .tptm-mobile-cards {
    display: block;
  }
  
  .tptm .tptm-mobile-card {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  }
  
  .tptm .tptm-mobile-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f0f0f0;
  }
  
  .tptm .tptm-mobile-card-title {
    font-weight: 600;
    color: #333;
    font-size: 0.9rem;
  }
  
  .tptm .tptm-mobile-card-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
  }
  
  .tptm .tptm-mobile-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
  }
  
  .tptm .tptm-mobile-card-label {
    font-weight: 500;
    color: #666;
    font-size: 0.85rem;
  }
  
  .tptm .tptm-mobile-card-value {
    color: #333;
    font-size: 0.85rem;
  }
  
  .tptm .tptm-mobile-card-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
  }
  
  .tptm .tptm-mobile-card-controls .tptm-qty-select {
    width: 100%;
    max-width: 120px;
  }
  
  .tptm .tptm-mobile-card-controls .tptm-btn {
    width: 100%;
  }
  
  /* Modal responsive */
  .tptm .tptm-modal-content {
    width: 95vw;
    margin: 10px;
  }
  
  .tptm .tptm-modal-body {
    padding: 10px;
  }
  
  /* QR Scanner mobile */
  #tptm-qr-target {
    min-height: 250px;
  }
  
  /* Order items mobile */
  .tptm .tptm-item-stats { 
    flex-direction: column; 
    gap: 8px; 
  }
  
  .tptm .tptm-item-controls { 
    flex-direction: column; 
    align-items: flex-start; 
    gap: 8px;
  }
  
  .tptm .tptm-item-controls .tptm-qty-select { 
    width: 100%; 
    max-width: 120px; 
  }
  
  /* Buttons mobile */
  .tptm .tptm-btn {
    padding: 12px 16px;
    font-size: 0.9rem;
    min-height: 48px; /* Larger touch targets on mobile */
    width: 100%;
    margin-bottom: 8px;
  }
  
  /* Product cards touch-friendly */
  .tptm .tptm-product {
    min-height: 60px; /* Larger touch targets */
    padding: 12px;
  }
  
  /* Search mobile */
  .tptm #tptm-search {
    padding: 12px;
    font-size: 16px; /* Prevent zoom on iOS */
  }
  
  /* Pagination mobile */
  .tptm .tptm-pagination {
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }
}

/* Extra small screens */
@media (max-width: 480px) {
  .tptm .tptm-product {
    padding: 6px;
  }
  
  .tptm .tptm-product-thumb {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
  }
  
  .tptm .tptm-table {
    min-width: 500px;
  }
  
  .tptm .tptm-table thead th,
  .tptm .tptm-table tbody td {
    padding: 6px 4px;
    font-size: 0.8rem;
  }
  
  .tptm .tptm-modal-content {
    width: 98vw;
    margin: 5px;
  }
  
  #tptm-qr-target {
    min-height: 200px;
  }
}