/* فونت و ریست استایل‌ها */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, "IranSans", sans-serif;
  -webkit-font-smoothing: antialiased;
}

:root {
  --primary: #1976d2;
  --primary-hover: #1565c0;
  --primary-light: #e3f2fd;
  --secondary: #00897b;
  --danger: #d32f2f;
  --danger-light: #ffebee;
  --bg-page: #f4f6f9;
  --bg-card: #ffffff;
  --border: #e0e0e0;
  --text-main: #212121;
  --text-muted: #666666;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
}

body {
  background-color: var(--bg-page);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* هدر */
.header {
  background-color: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 10px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
}

.header-titles h1 {
  font-size: 17px;
  font-weight: 700;
  color: #1a237e;
}

.status-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 12px;
  margin-top: 2px;
}
.status-badge.connected {
  background-color: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}
.status-badge.connecting {
  background-color: #fff8e1;
  color: #f57f17;
  border: 1px solid #ffe082;
}
.status-badge.error {
  background-color: var(--danger-light);
  color: var(--danger);
  border: 1px solid #ffcdd2;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.store-badge {
  font-size: 12px;
  background: var(--bg-page);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 6px;
}

.btn-icon {
  background: #ffffff;
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-icon:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* بدنه اصلی */
.main-container {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* بخش کاتالوگ اقلام (راست) */
.catalog-section {
  flex: 1.5;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background-color: #ffffff;
  overflow: hidden;
}

.search-bar-container {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #fafafa;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  right: 12px;
  font-size: 15px;
  color: var(--text-muted);
}

.search-input-wrapper input {
  width: 100%;
  padding: 10px 38px 10px 36px;
  font-size: 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  outline: none;
  background-color: #ffffff;
  transition: border-color 0.2s;
}
.search-input-wrapper input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.12);
}

.btn-clear-search {
  position: absolute;
  left: 10px;
  background: transparent;
  border: none;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-muted);
}

.categories-scroll {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.categories-scroll::-webkit-scrollbar {
  height: 4px;
}
.categories-scroll::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

.chip {
  background: #ffffff;
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  color: var(--text-main);
  transition: all 0.2s;
}
.chip.active, .chip:hover {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* شبکه کالاها */
.products-grid {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  align-content: start;
}

.product-card {
  background: #ffffff;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: all 0.18s ease;
  box-shadow: var(--shadow-sm);
  min-height: 120px;
}
.product-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.product-card:active {
  transform: scale(0.98);
}

.product-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.product-name {
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.4;
  color: #111;
}

.product-unit-badge {
  font-size: 10.5px;
  background: var(--primary-light);
  color: var(--primary);
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  white-space: nowrap;
}

.product-card-bottom {
  margin-top: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.product-price {
  font-size: 14px;
  font-weight: 800;
  color: #2e7d32;
}
.product-price small {
  font-size: 10.5px;
  font-weight: 400;
  color: var(--text-muted);
}

.product-stock {
  font-size: 11px;
  color: var(--text-muted);
}

/* بخش فاکتور (چپ) */
.cart-section {
  flex: 1;
  min-width: 340px;
  max-width: 440px;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cart-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.cart-header h2 {
  font-size: 16px;
  font-weight: 700;
}

.btn-text-danger {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
}
.btn-text-danger:hover {
  text-decoration: underline;
}

.customer-box {
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  background: #fdfdfd;
  border-bottom: 1px solid var(--border);
}

.input-sm {
  flex: 1;
  padding: 7px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.input-sm:focus {
  border-color: var(--primary);
}

/* لیست اقلام سبد */
.cart-items-container {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cart-empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}
.cart-empty-icon {
  font-size: 40px;
  display: block;
  margin-bottom: 10px;
}
.cart-empty small {
  display: block;
  margin-top: 6px;
  font-size: 11.5px;
}

.cart-item-row {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cart-item-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.cart-item-title {
  font-size: 13px;
  font-weight: 600;
}
.cart-item-remove {
  color: var(--danger);
  border: none;
  background: transparent;
  font-size: 14px;
  cursor: pointer;
  padding: 2px 4px;
}

.cart-item-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.qty-stepper {
  display: flex;
  align-items: center;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.qty-btn {
  background: #f0f0f0;
  border: none;
  width: 28px;
  height: 28px;
  font-size: 15px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.qty-btn:hover {
  background: #e0e0e0;
}
.qty-input {
  width: 44px;
  text-align: center;
  border: none;
  outline: none;
  font-size: 13px;
  font-weight: 700;
}

.cart-item-subtotal {
  font-size: 13.5px;
  font-weight: 800;
  color: #111;
}

/* خلاصه فاکتور */
.cart-summary {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: #fafafa;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.summary-row.total-row {
  font-size: 16px;
  font-weight: 800;
  color: #1565c0;
  border-top: 1.5px dashed var(--border);
  padding-top: 8px;
}

.discount-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
}
.input-discount {
  width: 90px;
  padding: 4px 6px;
  font-size: 12.5px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

/* روش‌های پرداخت */
.payment-methods {
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  gap: 6px;
  border-top: 1px solid var(--border);
  background: #ffffff;
}

.pay-option {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  cursor: pointer;
}
.pay-option:has(input:checked) {
  background: var(--primary-light);
  border-color: var(--primary);
  font-weight: 700;
}

/* دکمه‌های اقدام */
.action-buttons {
  padding: 12px 16px;
  background: #ffffff;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-primary-large {
  background: #2e7d32;
  color: #ffffff;
  border: none;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
}
.btn-primary-large:hover {
  background: #1b5e20;
}

.secondary-actions {
  display: flex;
  gap: 8px;
}

.btn-secondary {
  flex: 1;
  background: #f5f5f5;
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-secondary:hover {
  background: #e0e0e0;
}

/* مدال‌ها */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.btn-close {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
}

.modal-body {
  padding: 18px;
}
.input-full {
  width: 100%;
  padding: 8px 12px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}
.hint {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}

/* استایل پرینت فاکتور */
.invoice-printable {
  padding: 18px;
  font-size: 12px;
  line-height: 1.6;
}

@media print {
  body * {
    visibility: hidden;
  }
  #printableInvoiceArea, #printableInvoiceArea * {
    visibility: visible;
  }
  #printableInvoiceArea {
    position: absolute;
    left: 0;
    top: 0;
    width: 80mm;
    margin: 0 auto;
    font-size: 11px;
    padding: 10px;
  }
  .no-print {
    display: none !important;
  }
}
