:root {
  --rfq-surface: #ffffff;
  --rfq-card-bg: #f8fafc;
  --rfq-line: #e2e8f0;
  --rfq-text: #0f172a;
  --rfq-text-sub: #334155;
  --rfq-text-muted: #64748b;
  --rfq-primary: #0f766e;
  --rfq-primary-hover: #115e59;
  --rfq-danger: #e11d48;
  --rfq-radius-lg: 14px;
  --rfq-radius-md: 8px;
  --rfq-radius-sm: 6px;
  --rfq-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* Dialog Shell & Backdrop */
.za-rfq {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(900px, calc(100vw - 28px));
  max-height: calc(100dvh - 36px);
  padding: 0;
  border: 1px solid #cbd5e1;
  border-radius: var(--rfq-radius-lg);
  background: var(--rfq-surface);
  color: var(--rfq-text);
  box-shadow: 0 20px 50px -10px rgba(15, 23, 42, 0.35);
  overflow: hidden;
  z-index: 99999;
}

.za-rfq::backdrop {
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.za-rfq[open] {
  display: block;
  animation: rfq-desktop-in 0.24s var(--rfq-ease);
}

@keyframes rfq-desktop-in {
  from { opacity: 0; transform: scale(0.97) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.za-rfq-shell {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 #f8fafc;
}

/* Header */
.za-rfq header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: #f8fafc;
  border-bottom: 1px solid var(--rfq-line);
}

.za-rfq-kicker {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--rfq-primary);
  margin-bottom: 1px;
}

.za-rfq header h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f172a;
}

.za-rfq header p {
  margin: 0;
  font-size: 0.75rem;
  color: var(--rfq-text-muted);
  line-height: 1.4;
}

.za-rfq-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: 1px solid var(--rfq-line);
  border-radius: var(--rfq-radius-sm);
  background: #ffffff;
  color: var(--rfq-text-sub);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.za-rfq-close:hover {
  background: #fee2e2;
  color: var(--rfq-danger);
  border-color: #fecdd3;
}

/* Form Sections */
.za-rfq form {
  padding: 12px 20px 16px;
}

.za-rfq-section {
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
}

.za-rfq-section:last-of-type {
  border-bottom: none;
}

.za-sec-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.za-rfq-section h3 {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 800;
  color: #1e293b;
}

.za-sec-head h3 {
  margin: 0;
}

.za-rfq-section h3 span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 19px;
  height: 19px;
  border-radius: 5px;
  background: var(--rfq-primary);
  color: #ffffff;
  font-size: 0.7rem;
  font-weight: 800;
}

.za-btn-add-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  font-family: inherit;
  color: #ffffff;
  background: var(--rfq-primary);
  border: 1px solid transparent;
  border-radius: var(--rfq-radius-sm);
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(15, 118, 110, 0.2);
  transition: all 0.15s ease;
}

.za-btn-add-item:hover {
  background: var(--rfq-primary-hover);
  transform: translateY(-1px);
}

/* Grids */
.za-rfq-grid {
  display: grid;
  gap: 8px 12px;
}

.za-rfq-grid-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.za-rfq-grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.za-rfq label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.za-rfq label.wide {
  grid-column: 1 / -1;
}

.za-rfq label.wide-2 {
  grid-column: span 2;
}

.za-lbl {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--rfq-text-sub);
}

.req {
  color: var(--rfq-danger);
  font-size: 0.85rem;
  line-height: 1;
}

/* Inputs & Form Controls */
.za-rfq input,
.za-rfq select,
.za-rfq textarea {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 0.8rem;
  color: var(--rfq-text);
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: var(--rfq-radius-sm);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  line-height: 1.35;
}

/* Custom Dropdown Styling with clear Arrow indicator */
.za-rfq select,
.za-select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230f766e' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: left 8px center !important;
  background-size: 14px 14px !important;
  padding-left: 28px !important;
  padding-right: 8px !important;
  cursor: pointer;
}

.za-rfq input::placeholder,
.za-rfq textarea::placeholder {
  color: #94a3b8;
  font-size: 0.74rem;
}

.za-rfq input:focus,
.za-rfq select:focus,
.za-rfq textarea:focus {
  outline: none;
  border-color: var(--rfq-primary);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.15);
}

.za-rfq textarea {
  resize: vertical;
  min-height: 48px;
}

/* Field Error Styling */
.za-field-err,
.za-rfq small[data-error] {
  display: none;
  color: var(--rfq-danger) !important;
  font-size: 0.7rem !important;
  font-weight: 700 !important;
  margin-top: 2px !important;
  line-height: 1.3 !important;
}

.za-rfq input.has-error,
.za-rfq select.has-error,
.za-rfq textarea.has-error {
  border-color: var(--rfq-danger) !important;
  background-color: #fff1f2 !important;
  box-shadow: 0 0 0 2px rgba(225, 29, 72, 0.2) !important;
}

/* Items Dynamic Table Header & Container */
.za-items-header-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  padding: 0 2px;
}

.za-items-bar-title {
  font-size: 0.74rem;
  font-weight: 750;
  color: var(--rfq-text-sub);
}

.za-items-container {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--rfq-radius-md);
  padding: 8px 10px;
}

.za-items-table-wrap {
  overflow-x: auto;
  border-radius: 6px;
}

.za-items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.za-items-table th {
  padding: 6px 8px;
  font-weight: 800;
  color: var(--rfq-text-sub);
  text-align: right;
  background: #edf2f7;
  border-bottom: 1px solid #cbd5e1;
}

.za-items-table td {
  padding: 4px 4px;
}

.za-items-table input,
.za-items-table select {
  padding: 4px 6px;
  font-size: 0.76rem;
  background: #ffffff;
}

.za-btn-del-row {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid #fecdd3;
  border-radius: 4px;
  background: #fff1f2;
  color: var(--rfq-danger);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  transition: all 0.15s ease;
}

.za-btn-del-row:disabled {
  opacity: 0.3;
  cursor: not-allowed;
  border-color: #e2e8f0;
  background: #f1f5f9;
  color: #94a3b8;
}

.za-btn-del-row:not(:disabled):hover {
  background: var(--rfq-danger);
  color: #ffffff;
}

/* Upload & Agreement Row */
.za-upload-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
  align-items: center;
}

.za-rfq-drop {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px dashed #94a3b8;
  border-radius: var(--rfq-radius-md);
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.15s ease;
}

.za-rfq-drop:hover {
  border-color: var(--rfq-primary);
  background: #f0fdfa;
}

.za-drop-icon { font-size: 1rem; }
.za-drop-text { font-size: 0.72rem; font-weight: 700; color: #334155; flex: 1; }
.za-rfq-drop small { font-size: 0.65rem; color: var(--rfq-text-muted); }
.za-rfq-drop input[type="file"] { display: none; }
.za-rfq-files { margin-top: 4px; font-size: 0.7rem; color: var(--rfq-primary); font-weight: 600; }

/* Checkboxes — INLINE ALIGNMENT */
.za-rfq-agreements {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.za-rfq-check {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 8px !important;
  cursor: pointer;
  margin: 0 !important;
}

.za-rfq-check input[type="checkbox"] {
  width: 16px !important;
  height: 16px !important;
  min-width: 16px;
  margin: 0 !important;
  accent-color: var(--rfq-primary);
  cursor: pointer;
}

.za-rfq-check span {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--rfq-text-sub);
  line-height: 1.2;
}

.za-rfq-hp {
  position: absolute !important;
  inset-inline-start: -10000px !important;
}

/* Status Messages & Big Success Box */
.za-rfq-result {
  display: none;
  margin: 8px 0 0;
  padding: 8px 12px;
  border-radius: var(--rfq-radius-sm);
  font-size: 0.76rem;
  font-weight: 700;
}

.za-rfq-result.err { display: block; background: #fff1f2; color: #9f1239; border: 1px solid #fecdd3; }

.za-rfq-success-card {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  text-align: center !important;
  padding: 24px 20px !important;
  margin: 14px 0 6px !important;
  background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%) !important;
  border: 2px solid #86efac !important;
  border-radius: 12px !important;
  box-shadow: 0 10px 25px -5px rgba(22, 101, 52, 0.15) !important;
  animation: zaSuccessPop 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

@keyframes zaSuccessPop {
  from { opacity: 0; transform: scale(0.95) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.za-success-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #16a34a;
  color: #ffffff;
  font-size: 1.5rem;
  font-weight: 900;
  margin-bottom: 10px;
  box-shadow: 0 4px 12px rgba(22, 163, 74, 0.3);
}

.za-success-title {
  font-size: 1.05rem !important;
  font-weight: 900 !important;
  color: #14532d !important;
  margin-bottom: 6px !important;
  line-height: 1.4 !important;
}

.za-success-text {
  font-size: 0.88rem !important;
  font-weight: 700 !important;
  color: #166534 !important;
  line-height: 1.6 !important;
  margin-bottom: 10px !important;
}

.za-success-badge {
  display: inline-block;
  padding: 4px 12px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #bbf7d0;
  border-radius: 20px;
  font-size: 0.78rem;
  color: #15803d;
  font-weight: 600;
}

.za-success-badge b {
  color: #0f172a;
  margin-right: 4px;
}

/* Footer */
.za-rfq footer {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  background: #f8fafc;
  border-top: 1px solid var(--rfq-line);
}

.za-rfq-foot-info {
  font-size: 0.72rem;
  color: var(--rfq-text-muted);
  font-weight: 600;
}

.za-rfq-foot-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.za-rfq-cancel,
.za-rfq-submit {
  padding: 6px 14px;
  border-radius: var(--rfq-radius-sm);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.za-rfq-cancel {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: var(--rfq-text-sub);
}

.za-rfq-cancel:hover { background: #f1f5f9; }

.za-rfq-submit {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid transparent;
  background: var(--rfq-primary);
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 118, 110, 0.2);
}

.za-rfq-submit:hover { background: var(--rfq-primary-hover); }
.za-rfq-submit:disabled { opacity: 0.65; cursor: wait; }

.za-rfq-submit i {
  display: none;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: rfq-spin 0.65s linear infinite;
}

.za-rfq-submit:disabled i { display: inline-block; }

@keyframes rfq-spin { to { transform: rotate(360deg); } }

/* =========================================================================
   TABLET RESPONSIVENESS (max-width: 900px)
   ========================================================================= */
@media (max-width: 900px) {
  .za-rfq {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
  }
  .za-rfq-grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .za-rfq-grid-3 {
    grid-template-columns: 1fr 1fr;
  }
  .za-rfq label.wide-2 {
    grid-column: 1 / -1;
  }
}

/* =========================================================================
   MOBILE RESPONSIVENESS (max-width: 640px)
   ========================================================================= */
@media(max-width:640px) {
  .za-rfq {
    position: fixed;
    inset: 0;
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    border-radius: 0;
    border: none;
    margin: 0;
  }

  .za-rfq-shell {
    max-height: 100dvh;
    height: 100dvh;
  }

  .za-rfq header {
    padding: 10px 14px;
  }

  .za-rfq header h2 {
    font-size: 1.05rem;
  }

  .za-rfq form {
    padding: 10px 12px 14px;
  }

  .za-rfq-grid-4,
  .za-rfq-grid-3 {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .za-rfq label.wide-2 {
    grid-column: auto;
  }

  /* Transform table rows into stacked cards on mobile */
  .za-items-table thead {
    display: none;
  }

  .za-items-table,
  .za-items-table tbody,
  .za-items-table tr,
  .za-items-table td {
    display: block;
    width: 100% !important;
    box-sizing: border-box;
  }

  .za-items-table tr {
    position: relative;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 10px 6px;
    margin-bottom: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  }

  .za-items-table td {
    padding: 2px 0;
    border: none;
  }

  .za-items-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--rfq-text-sub);
    margin-bottom: 2px;
  }

  .za-items-table td.za-td-del {
    display: flex;
    justify-content: flex-end;
    padding-top: 4px;
    margin-top: 4px;
    border-top: 1px dashed #e2e8f0;
  }

  .za-items-table td.za-td-del::before {
    content: "حذف این قلم:";
    font-size: 0.7rem;
    color: var(--rfq-danger);
    font-weight: 600;
    margin-left: auto;
    align-self: center;
  }

  .za-upload-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .za-rfq footer {
    flex-direction: column;
    padding: 8px 14px max(8px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  .za-rfq-foot-info {
    text-align: center;
    font-size: 0.68rem;
  }

  .za-rfq-foot-actions {
    width: 100%;
  }

  .za-rfq-cancel {
    display: none;
  }

  .za-rfq-submit {
    width: 100%;
    justify-content: center;
    padding: 8px;
    font-size: 0.85rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .za-rfq[open],
  .za-rfq-submit i {
    animation: none;
  }
}
