/**
 * SimCard Manager - Order History & Raw Lines Stylesheet (order_history.css)
 * استایل‌های پیشرفته و هماهنگ‌شده بخش سابقه سفارشات، ردیابی خطوط خام و شکارچی تخفیف اول
 */

.history-workspace {
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
  direction: rtl;
}

.history-workspace [hidden] {
  display: none !important;
}

/* ================= 1. KPI CARDS ROW ================= */
.history-kpi-row {
  margin-bottom: 20px;
}

.history-kpi-row .kpi-card {
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.history-kpi-row .kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.4);
}

.history-kpi-row .kpi-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 16px var(--primary-glow);
  background: var(--bg-card-hover);
}

/* ================= 2. HUNTER PRESETS PANEL ================= */
.hunter-presets-panel {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.7), rgba(15, 23, 42, 0.9));
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hunter-presets-title {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hunter-presets-title span {
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  display: flex;
  align-items: center;
  gap: 6px;
}

.hunter-presets-title small {
  color: var(--text-muted);
  font-size: 12px;
}

.hunter-presets-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.preset-chip {
  padding: 7px 14px;
  border-radius: 20px;
  background: #0d131f;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 0.2s ease;
  font-family: inherit;
}

.preset-chip:hover {
  background: #1e293b;
  border-color: var(--primary);
  color: #fff;
  transform: translateY(-1px);
}

.preset-chip.active {
  background: rgba(16, 185, 129, 0.15);
  border-color: #10b981;
  color: #34d399;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.25);
}

/* ================= 3. FILTER PANEL ================= */
.history-filter-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}

.filter-section-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-dim);
  min-width: 100px;
  white-space: nowrap;
}

/* Service Tabs */
.service-tabs-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.history-service-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.history-service-tab {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  background: #0d131f;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
  font-family: inherit;
}

.history-service-tab:hover {
  background: #1c263c;
  color: #fff;
}

.history-service-tab[aria-pressed="true"],
.history-service-tab.active {
  background: #1e293b;
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.2);
}

/* Branded Service Active Colors */
.history-service-tab[data-service="snappfood"][aria-pressed="true"] { border-color: var(--snappfood); color: var(--snappfood); box-shadow: 0 0 10px rgba(236, 72, 153, 0.25); }
.history-service-tab[data-service="digikala_jet"][aria-pressed="true"] { border-color: var(--digi-jet); color: var(--digi-jet); box-shadow: 0 0 10px rgba(168, 85, 247, 0.25); }
.history-service-tab[data-service="digikala"][aria-pressed="true"] { border-color: var(--digikala); color: var(--digikala); box-shadow: 0 0 10px rgba(239, 64, 86, 0.25); }
.history-service-tab[data-service="tapsi"][aria-pressed="true"] { border-color: var(--tapsi); color: var(--tapsi); box-shadow: 0 0 10px rgba(255, 107, 0, 0.25); }
.history-service-tab[data-service="tapsi_market"][aria-pressed="true"] { border-color: var(--tmarket); color: var(--tmarket); box-shadow: 0 0 10px rgba(245, 158, 11, 0.25); }
.history-service-tab[data-service="snappmarket"][aria-pressed="true"] { border-color: var(--snappmarket); color: var(--snappmarket); box-shadow: 0 0 10px rgba(225, 29, 72, 0.25); }
.history-service-tab[data-service="snapp"][aria-pressed="true"] { border-color: var(--snapp); color: var(--snapp); box-shadow: 0 0 10px rgba(0, 209, 112, 0.25); }
.history-service-tab[data-service="okala"][aria-pressed="true"] { border-color: var(--okala); color: var(--okala); box-shadow: 0 0 10px rgba(239, 57, 78, 0.25); }
.history-service-tab[data-service="banimode"][aria-pressed="true"] { border-color: var(--banimode); color: var(--banimode); box-shadow: 0 0 10px rgba(99, 102, 241, 0.25); }

/* Subservice / Food Vendor Chips */
.subservice-chips-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.subservice-chip {
  padding: 6px 14px;
  border-radius: 20px;
  background: #0d131f;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  font-family: inherit;
}

.subservice-chip:hover {
  background: #1e293b;
  color: #fff;
  border-color: var(--border-light);
}

.subservice-chip.active {
  background: rgba(236, 72, 153, 0.15);
  border-color: var(--snappfood);
  color: var(--snappfood);
  box-shadow: 0 0 10px rgba(236, 72, 153, 0.2);
}

/* Status Chips & Additional Controls */
.refine-filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.refine-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chip-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  background: #0d131f;
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  font-family: inherit;
}

.chip-btn:hover {
  background: #1c263c;
  color: #fff;
}

.chip-btn.active {
  background: #1e293b;
  border-color: var(--primary);
  color: var(--primary);
}

.chip-btn.chip-raw.active {
  background: rgba(16, 185, 129, 0.15);
  border-color: #10b981;
  color: #10b981;
}

.chip-btn.chip-ordered.active {
  background: rgba(96, 165, 250, 0.15);
  border-color: #60a5fa;
  color: #60a5fa;
}

.chip-btn.chip-unknown.active {
  background: rgba(245, 158, 11, 0.15);
  border-color: #f59e0b;
  color: #f59e0b;
}

.filter-select {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: #0d131f;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.filter-select:focus {
  border-color: var(--primary);
}

.history-support-text {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-inline-start: auto;
}

/* ================= 4. TABLE RESULTS ================= */
.history-results-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  margin-bottom: 24px;
}

.history-results-card .table-responsive {
  overflow-x: auto;
  max-width: 100%;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
  direction: rtl;
}

.history-table th,
.history-table td {
  padding: 14px 16px;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-color);
}

.history-table th {
  background: #0d131f;
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 700;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

.history-table tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.history-table tr:last-child td {
  border-bottom: none;
}

.history-table input[type="checkbox"] {
  accent-color: var(--primary);
  width: 17px;
  height: 17px;
  cursor: pointer;
}

/* Account Info Cell */
.history-account-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-phone {
  direction: ltr;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14.5px;
  font-weight: 700;
  font-family: Consolas, 'Courier New', monospace;
  color: var(--text-main);
  letter-spacing: 0.5px;
}

.history-meta-tags {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.history-account-name {
  font-size: 12px;
  color: var(--text-main);
  font-weight: 600;
}

.history-scope-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-muted);
}

/* History Badges & Matrix */
.history-badge {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.history-badge.raw {
  color: #10b981;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.history-badge.ordered {
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.history-badge.error {
  color: #fb923c;
  background: rgba(251, 146, 60, 0.12);
  border: 1px solid rgba(251, 146, 60, 0.3);
}

.history-badge.unknown {
  color: #94a3b8;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.history-meta {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-top: 3px;
}

.history-error {
  display: block;
  color: #fb923c;
  font-size: 11px;
  line-height: 1.6;
  margin-top: 4px;
}

/* Detailed Single Service Card */
.history-single-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  max-width: 320px;
}

/* All-Services Modern Chips Row */
.history-overview {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.history-service-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 11.5px;
  background: #0d131f;
  color: var(--text-main);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}

.history-service-status:hover {
  border-color: var(--primary);
  background: #1c263c;
  transform: translateY(-1px);
}

.history-row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.history-row-actions .btn {
  font-size: 12px;
  padding: 6px 12px;
}

.history-empty {
  padding: 60px 20px !important;
  text-align: center !important;
  color: var(--text-muted);
  line-height: 2;
}

.history-empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.8;
}

/* Table Footer */
.table-footer.history-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  background: #0d131f;
}

.pagination-info {
  font-size: 13px;
  color: var(--text-muted);
}

.pagination-controls {
  display: flex;
  gap: 8px;
}

/* ================= 5. FLOATING BULK ACTIONS BAR ================= */
.bulk-actions-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--primary);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6), 0 0 20px var(--primary-glow);
  border-radius: var(--radius-lg);
  padding: 12px 24px;
  z-index: 999;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
  from {
    transform: translate(-50%, 40px);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

.bulk-actions-inner {
  display: flex;
  align-items: center;
  gap: 20px;
}

.bulk-selected-count {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}

.bulk-actions-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Focus States */
.history-workspace button:focus-visible,
.history-workspace input:focus-visible,
.history-workspace select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ================= RESPONSIVE ================= */
.presets-chevron { display: inline-block; transition: transform 0.2s ease; }
details.hunter-presets-panel[open] .presets-chevron { transform: rotate(180deg); }
@media (max-width: 1024px) {
  .history-overview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
}

@media (max-width: 768px) {
  .history-kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
  }
  .history-kpi-row .kpi-card { padding: 10px 12px; min-width: 0; }
  .history-kpi-row .kpi-icon { width: 38px; height: 38px; font-size: 18px; }
  .history-kpi-row .kpi-value { font-size: 19px; }
  .history-kpi-row .kpi-label { font-size: 11px; line-height: 1.4; }
  .history-filter-panel {
    padding: 16px;
  }
  .hunter-presets-chips {
    overflow-x: auto;
    padding-bottom: 6px;
  }
  .preset-chip {
    white-space: nowrap;
  }
  .service-tabs-header,
  .subservice-chips-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .bulk-actions-bar {
    width: 90%;
    padding: 12px 16px;
  }
  .bulk-actions-inner {
    flex-direction: column;
    gap: 10px;
  }
  .bulk-actions-buttons {
    width: 100%;
  }
  .bulk-actions-buttons .btn {
    flex: 1;
  }
}
/* Compound history filters stay usable on narrow screens. */
.history-compound-filter { padding: 12px 0; }
.history-condition-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.history-condition-row .filter-select { min-width: 120px; flex: 1; }
#history-compound-editor[hidden] { display: none; }
.history-food-overview { display: grid; gap: 12px; min-width: 0; }
.history-food-table td { vertical-align: top; }
.history-food-total { padding: 10px; border-bottom: 1px solid var(--border-color); }
.history-food-total > strong { display: block; margin-bottom: 8px; }
.history-food-category-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.history-food-category-card { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 12px;
  min-width: 0; text-align: start; font: inherit; color: var(--text-main); background: rgba(15, 23, 42, .6);
  border: 1px solid var(--border-color); border-radius: 8px; overflow-wrap: anywhere; }
button.history-food-category-card { cursor: pointer; }
button.history-food-category-card:hover { border-color: var(--primary); }
@media (max-width: 1000px) { .history-food-category-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 480px) { .history-food-category-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 640px) {
  .history-food-table, .history-food-table thead, .history-food-table tbody { display: block; width: 100%; min-width: 0; }
  .history-food-table tr { display: grid; grid-template-columns: 36px minmax(0, 1fr); }
  .history-food-table th, .history-food-table td { width: auto !important; min-width: 0; }
  .history-food-table th:nth-child(n+3) { display: none; }
  .history-food-table td:nth-child(3), .history-food-table td:nth-child(4) { grid-column: 1 / -1; }
  .history-food-table .history-account-info { align-items: flex-start; }
}
