/* =========================================================
   ECHO ERP — SALES ADD / INVOICE CREATE
   Full Premium CSS Replacement
========================================================= */

/* =========================
   TOKENS
========================= */
:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --card-soft: #fbfdff;
  --text: #0f172a;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: #e6edf5;
  --line-2: #dbe4ee;

  --primary: #2563eb;
  --primary-2: #0b74de;
  --primary-soft: rgba(37, 99, 235, 0.10);

  --success: #16a34a;
  --success-soft: #ecfdf5;
  --success-line: #bbf7d0;

  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-line: #fecaca;

  --warn: #b45309;
  --warn-soft: #fff7ed;
  --warn-line: #fed7aa;

  --shadow-sm: 0 4px 12px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 10px 30px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.08);

  --radius-xs: 10px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-xl: 24px;

  --h-input: 50px;
}

/* =========================
   BASE
========================= */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--text);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
  color: var(--text);
}

label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 800;
  color: #334155;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--text);
  border-radius: 16px;
  transition:
    border-color .18s ease,
    box-shadow .18s ease,
    background-color .18s ease,
    transform .12s ease;
}

input,
select {
  height: var(--h-input);
  padding: 0 14px;
}

textarea {
  min-height: 96px;
  padding: 12px 14px;
  resize: vertical;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-2);
}

input:hover,
select:hover,
textarea:hover {
  border-color: #bfd5ff;
  background: #fcfdff;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
  background: #fff;
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-left: 42px;
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, #64748b 50%),
    linear-gradient(135deg, #64748b 50%, transparent 50%);
  background-position:
    calc(16px) calc(50% - 3px),
    calc(10px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

a {
  color: inherit;
  text-decoration: none;
}

/* =========================
   MAIN LAYOUT
========================= */
.sales-layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.summary-col {
  position: relative;
  min-width: 0;
}

.summary-col .card {
  position: sticky;
  top: 16px;
}

.right-col {
  display: grid;
  gap: 20px;
  min-width: 0;
}

/* لو عندك sales-grid مستخدم في أجزاء أخرى */
.sales-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

.sales-grid.full {
  grid-template-columns: 2fr 1fr;
}

/* =========================
   CARD SYSTEM
========================= */
.card {
  position: relative;
  background: linear-gradient(180deg, var(--card) 0%, var(--card-soft) 100%);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 20px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 4px;
  background: linear-gradient(90deg, #2563eb 0%, #60a5fa 50%, #93c5fd 100%);
  opacity: .95;
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.card h3,
.card h4 {
  margin: 0 0 16px;
  color: var(--text);
  letter-spacing: -0.02em;
}

.card h3 {
  font-size: 24px;
  font-weight: 900;
}

.card h4 {
  font-size: 20px;
  font-weight: 900;
}

/* =========================
   CUSTOMER CARD
========================= */
.customer-card {
  padding: 24px;
}

.customer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.field-box {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.field-box label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.field-box:has(input[required]) label::after,
.field-box:has(select[required]) label::after {
  content: " *";
  color: var(--danger);
  font-weight: 900;
}

.identity-slot>div {
  width: 100%;
}

#national_id_wrap,
#tax_reg_wrap {
  animation: fadeSlideIn .18s ease;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* =========================
   PRODUCT SEARCH CARD
========================= */
#product_search {
  font-weight: 700;
}

.suggest-box {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow-md);
  display: none;
  max-height: 320px;
  overflow: auto;
}

.suggest-item {
  padding: 14px 14px;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
  transition: background-color .15s ease;
}

.suggest-item:last-child {
  border-bottom: none;
}

.suggest-item:hover {
  background: #f8fbff;
}

.suggest-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.suggest-top strong {
  font-size: 14px;
  font-weight: 900;
  color: var(--text);
}

.suggest-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

/* =========================
   BADGES / ALERTS / MUTED
========================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  padding: 4px 10px;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
}

.badge.ok {
  border-color: var(--success-line);
  background: var(--success-soft);
  color: #166534;
}

.badge.no {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: #991b1b;
}

.alert {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
  display: none;
  border: 1px solid transparent;
}

.alert.warn {
  background: var(--warn-soft);
  color: #9a3412;
  border-color: var(--warn-line);
}

.alert.err {
  background: var(--danger-soft);
  color: #991b1b;
  border-color: var(--danger-line);
}

.muted {
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  border: 1px dashed #dbe2ea;
  border-radius: 18px;
  background: #f8fbff;
  text-align: center;
  padding: 14px;
}

/* =========================
   INVOICE ITEMS WRAPPER
========================= */
.invoice-items {
  display: grid;
  gap: 14px;
}

/* =========================
   INVOICE ITEM CARD
========================= */
.invoice-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.inv-name {
  font-weight: 900;
  font-size: 15px;
  margin-bottom: 12px;
  color: var(--text);
  line-height: 1.5;
}

.inv-selectors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.inv-selectors select {
  height: 48px;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 700;
}

.inv-actions {
  display: grid;
  grid-template-columns: auto 1fr 1fr 42px;
  gap: 14px;
  align-items: center;
}

.qtybox,
.qty-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qtybtn,
.qty-box button {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
  transition: .15s ease;
}

.qtybtn:hover,
.qty-box button:hover {
  border-color: #bfd5ff;
  background: #f8fbff;
}

.qty,
.qty-box input {
  width: 76px;
  height: 42px;
  text-align: center;
  border-radius: 12px;
  font-weight: 800;
}

.line-total {
  font-weight: 900;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #eef2f7;
  padding: 12px 0;
}

.item-row:last-child {
  border-bottom: none;
}

/* =========================
   BUTTONS
========================= */
.btn {
  border: none;
  border-radius: 14px;
  padding: 10px 14px;
  font-weight: 900;
  cursor: pointer;
  transition:
    transform .12s ease,
    box-shadow .18s ease,
    opacity .18s ease,
    background-color .18s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn.primary {
  background: linear-gradient(180deg, #1d6ef2 0%, #0b74de 100%);
  color: #fff;
  box-shadow: 0 8px 18px rgba(11, 116, 222, 0.24);
}

.btn.dark {
  background: #0f172a;
  color: #fff;
}

.btn.ghost {
  background: #f1f5f9;
  color: #0f172a;
}

.btn.del {
  background: #ef4444;
  color: #fff;
}

.btn.small {
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
}

.btn.full {
  width: 100%;
}

/* =========================
   SUMMARY CARD
========================= */
.summary-col .card {
  padding: 22px;
}

.summary-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.summary-title {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.summary-title h3 {
  margin: 0;
}

.total-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  font-weight: 900;
  margin-top: 10px;
  padding: 10px 0;
}

.total-line+.total-line {
  border-top: 1px dashed #e2e8f0;
}

.total-line .label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.total-line .value {
  color: var(--text);
  font-size: 16px;
  font-weight: 900;
}

.sum-box {
  margin-top: 12px;
  padding: 14px;
  border: 1px dashed #dbe5f0;
  border-radius: 18px;
  background: #f8fbff;
}

.sum-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.sum-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* =========================
   SERVICE / DISCOUNT / TAX / SHIPPING
========================= */
.tax-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tax-check,
.tax-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tax-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.inline-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 10px;
}

.box-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-weight: 900;
}

.box-toggle .icon {
  width: 30px;
  height: 30px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: #eef4ff;
  color: var(--primary);
  font-weight: 900;
}

.paybox {
  margin-top: 14px;
  padding: 14px;
  border: 1px dashed #d9e5f3;
  border-radius: 18px;
  background: #f8fbff;
}

/* =========================
   PAYMENT UI
========================= */
.payrow {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 10px;
}

.payrow>* {
  flex: 1;
  min-width: 140px;
}

.payrow .small {
  min-width: 120px;
  flex: 0 0 120px;
}

.payrow .mini {
  min-width: 95px;
  flex: 0 0 95px;
}

.payrow input,
.payrow select {
  height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  background: #fff;
}

.pay-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.payhint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  font-weight: 700;
}

.paywarn {
  display: none;
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--warn-soft);
  color: #9a3412;
  border: 1px solid var(--warn-line);
  font-size: 13px;
  font-weight: 700;
}

/* =========================
   QUICK INFO BOXES / HEAD NUMBERS
========================= */
.metric-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 84px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
}

.metric-box .label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 800;
}

.metric-box .value {
  margin-top: 8px;
  font-size: 32px;
  line-height: 1;
  font-weight: 900;
  color: var(--primary);
}

/* =========================
   HELPERS
========================= */
.row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.row>* {
  flex: 1;
  min-width: 180px;
}

.hidden {
  display: none !important;
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

.w-full {
  width: 100%;
}

.mt-0 {
  margin-top: 0 !important;
}

.mt-8 {
  margin-top: 8px !important;
}

.mt-10 {
  margin-top: 10px !important;
}

.mt-12 {
  margin-top: 12px !important;
}

.mt-16 {
  margin-top: 16px !important;
}

.mt-20 {
  margin-top: 20px !important;
}

.mb-0 {
  margin-bottom: 0 !important;
}

/* =========================
   SCROLLBAR
========================= */
.suggest-box::-webkit-scrollbar {
  width: 10px;
}

.suggest-box::-webkit-scrollbar-thumb {
  background: #d7e2ef;
  border-radius: 999px;
}

.suggest-box::-webkit-scrollbar-track {
  background: transparent;
}

/* =========================
   RESPONSIVE
========================= */
@media (max-width: 1200px) {
  .sales-layout {
    grid-template-columns: 340px minmax(0, 1fr);
  }
}

@media (max-width: 1100px) {
  .sales-layout {
    grid-template-columns: 1fr;
  }

  .summary-col .card {
    position: static;
  }
}

@media (max-width: 900px) {

  .sales-grid,
  .sales-grid.full {
    grid-template-columns: 1fr;
  }

  .customer-grid {
    grid-template-columns: 1fr;
  }

  .inv-selectors {
    grid-template-columns: 1fr;
  }

  .inv-actions {
    grid-template-columns: 1fr;
  }

  .inline-fields {
    grid-template-columns: 1fr;
  }

  .card {
    border-radius: 20px;
    padding: 18px;
  }

  .customer-card {
    padding: 18px;
  }

  .card h3 {
    font-size: 21px;
  }

  .card h4 {
    font-size: 18px;
  }

  input,
  select {
    height: 48px;
  }
}

@media (max-width: 640px) {
  .payrow {
    flex-direction: column;
    align-items: stretch;
  }

  .payrow>*,
  .payrow .small,
  .payrow .mini {
    min-width: 100%;
    flex: 1 1 100%;
  }

  .sum-actions,
  .pay-actions,
  .sum-row,
  .row {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }
}