:root {
  --cds-bg: #ffffff;
  --cds-bg-2: #f4f4f4;
  --cds-text: #161616;
  --cds-text-2: #525252;
  --cds-border: #e0e0e0;
  --cds-border-strong: #161616;
  --cds-blue: #0f62fe;
  --cds-blue-dark: #002d9c;
  --cds-green: #24a148;
  --cds-red: #da1e28;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: #f5f5f4;
  color: var(--cds-text);
  font-family: 'IBM Plex Sans', sans-serif;
  direction: rtl;
}

.mono { font-family: 'IBM Plex Mono', monospace; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

input[type=text], input[type=number], input[type=email], textarea, .track-search input, .pay-form input {
  border: 1px solid var(--cds-border);
  border-radius: 4px;
  padding: 9px 10px;
  font-size: 14px;
  background: #fff;
  color: var(--cds-text);
  width: 100%;
}
input:focus, textarea:focus { outline: none; border-color: var(--cds-blue); }
.money-input { text-align: right; }

/* ---------- App shell ---------- */

.app-header {
  background: var(--cds-text);
  color: #fff;
  padding: 18px 28px;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.app-header .brand { font-weight: 700; font-size: 20px; letter-spacing: -0.01em; }
.app-header .tagline { font-size: 13px; color: #c6c6c6; }

.app-tabs {
  display: flex;
  gap: 4px;
  padding: 0 28px;
  background: var(--cds-bg);
  border-bottom: 1px solid var(--cds-border);
}
.app-tab {
  border: none;
  background: none;
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--cds-text-2);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  text-decoration: none;
}
.app-tab.active { color: var(--cds-text); border-bottom-color: var(--cds-blue); }

.app-main {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px;
}

.card {
  background: var(--cds-bg);
  border: 1px solid var(--cds-border);
  border-radius: 6px;
  padding: 24px;
  margin-bottom: 20px;
}
.card h2 { font-size: 16px; margin: 0 0 16px; }
.card h3 { font-size: 13px; color: var(--cds-text-2); margin: 24px 0 12px; letter-spacing: .02em; }

/* ---------- Form ---------- */

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--cds-text-2); }
.field textarea { resize: vertical; min-height: 64px; }
.field.span-2 { grid-column: 1 / -1; }

.items-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
.items-table th {
  text-align: right;
  font-size: 11px;
  color: var(--cds-text-2);
  font-weight: 500;
  padding: 6px 6px;
  border-bottom: 1px solid var(--cds-border);
}
.items-table td { padding: 4px; vertical-align: top; }
.items-table input { padding: 7px 8px; font-size: 13px; }
.items-table td.col-remove { width: 32px; text-align: center; }
.items-table td.col-comp { text-align: center; }
.items-table td.col-comp input { width: auto; }

.btn {
  border: 1px solid var(--cds-text);
  background: var(--cds-text);
  color: #fff;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { opacity: .88; }
.btn.primary { background: var(--cds-blue); border-color: var(--cds-blue); }
.btn.ghost { background: transparent; color: var(--cds-text); }
.btn.small { padding: 6px 12px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.row-actions { display: flex; gap: 10px; align-items: center; margin-top: 12px; }

.live-totals {
  margin-top: 16px;
  padding: 14px 16px;
  background: var(--cds-bg-2);
  border-radius: 4px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.live-totals .grand { font-weight: 700; font-size: 15px; border-top: 1px solid var(--cds-border); padding-top: 6px; margin-top: 2px; }
.live-totals .line { display: flex; justify-content: space-between; }

.msg { font-size: 13px; padding: 10px 12px; border-radius: 4px; margin-bottom: 14px; }
.msg.error { background: #fff1f1; color: var(--cds-red); border: 1px solid #ffd7d9; }
.msg.success { background: #defbe6; color: #0e6027; border: 1px solid #a7f0ba; }

/* ---------- Tracking ---------- */

.track-search { display: flex; gap: 10px; margin-bottom: 4px; }
.track-search input { flex: 1; }

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
}
.status-badge.pending { background: #fff8e1; color: #8a6100; }
.status-badge.paid { background: #defbe6; color: #0e6027; }

/* ---------- Invoice/receipt result actions ---------- */

.result-actions { display: flex; gap: 10px; align-items: center; margin: 0 0 16px; flex-wrap: wrap; }
.result-actions .spacer { flex: 1; }

.pay-form { display: flex; gap: 10px; align-items: center; margin-top: 14px; }
.pay-form input { flex: 1; }

.pay-options { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; }
.pay-option { border: 1px solid var(--cds-border); border-radius: 6px; padding: 16px; }
.pay-option-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.pay-option-desc { font-size: 12px; color: var(--cds-text-2); margin: 0 0 12px; line-height: 1.7; }
@media (max-width: 700px) { .pay-options { grid-template-columns: 1fr; } }

/* ---------- Printable invoice/receipt sheet ---------- */

.inv-sheet-wrap {
  background: #e8e8e6;
  padding: 24px;
  border-radius: 6px;
  overflow-x: auto;
}

.inv-sheet {
  width: 210mm;
  margin: 0 auto;
  background: var(--cds-bg);
  color: var(--cds-text);
  box-shadow: 0 2px 10px rgba(20, 20, 19, 0.15);
  border: 1px solid var(--cds-border);
  padding: 40px 44px 28px;
  display: flex;
  flex-direction: column;
}

.inv-topbar { height: 4px; background: var(--cds-blue); margin: -40px -44px 24px; }

.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--cds-border-strong);
}
.inv-brand { font-weight: 700; font-size: 26px; letter-spacing: -0.01em; }
.inv-domain { font-size: 11px; color: var(--cds-text-2); margin-top: 2px; }
.inv-meta { text-align: left; }
.inv-doctitle { font-weight: 600; font-size: 16px; }
.inv-meta .mono { font-size: 11px; color: var(--cds-text-2); margin-top: 4px; display: block; }
.inv-status { display: inline-block; margin-top: 6px; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.inv-status-pending { background: #fff8e1; color: #8a6100; }
.inv-status-paid { background: #defbe6; color: #0e6027; }

.inv-parties { padding: 14px 0; border-bottom: 1px solid var(--cds-border); }
.inv-parties-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; padding: 14px 0; border-bottom: 1px solid var(--cds-border); }
.inv-label { font-size: 10px; letter-spacing: .08em; color: var(--cds-text-2); margin-bottom: 5px; }
.inv-party-name { font-weight: 600; font-size: 14px; }
.inv-party-company { font-weight: 500; color: var(--cds-text-2); }
.inv-party-detail { font-size: 12px; color: var(--cds-text-2); margin-top: 3px; line-height: 1.7; }

.inv-table { width: 100%; border-collapse: collapse; margin-top: 16px; }
.inv-table th, .inv-table td { text-align: right; padding: 9px 12px; }
.inv-table th { background: var(--cds-text); color: #fff; font-weight: 500; font-size: 12px; letter-spacing: .02em; }
.inv-table td { border-bottom: 1px solid var(--cds-border); font-size: 13px; color: var(--cds-text); }
.inv-table tbody tr:nth-child(even) td { background: var(--cds-bg-2); }
.inv-table tr:last-child td { border-bottom: 1px solid var(--cds-border-strong); }
.inv-table .col-row { width: 32px; }
.inv-table .col-period { width: 70px; }
.inv-table .col-price { width: 90px; }
.inv-table .col-qty { width: 50px; }
.inv-table .col-total { width: 100px; }
.inv-strike { text-decoration: line-through; color: var(--cds-text-2); margin-left: 6px; }

.inv-totals-wrap { display: flex; justify-content: flex-start; margin-top: 14px; }
.inv-totals { width: 300px; }
.inv-totals-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13px; }
.inv-totals-tax { border-top: 1px solid var(--cds-border); }
.inv-totals-grand { padding: 9px 0; font-size: 15px; font-weight: 700; border-top: 2px solid var(--cds-text); margin-top: 2px; }

.inv-payment { margin-top: 18px; padding: 14px 16px; background: var(--cds-bg-2); border-right: 3px solid var(--cds-blue); }
.inv-payment-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; font-size: 13px; }
.inv-payment-key { color: var(--cds-text-2); font-size: 11px; margin-bottom: 2px; }
.inv-payment-val { font-weight: 600; direction: ltr; text-align: right; }
.inv-payment-track { margin-top: 10px; font-size: 11px; color: var(--cds-text-2); }

.inv-terms { margin-top: 18px; font-size: 11px; color: var(--cds-text-2); line-height: 1.8; }
.inv-terms-title { font-weight: 600; color: var(--cds-text); font-size: 11px; margin-bottom: 4px; }

.inv-sign-row { display: flex; justify-content: space-between; margin-top: 28px; padding-top: 20px; }
.inv-sign-box { width: 220px; text-align: center; border-top: 1px solid var(--cds-border-strong); padding-top: 6px; font-size: 11px; color: var(--cds-text-2); }

.inv-footer {
  margin-top: 20px;
  padding-top: 10px;
  border-top: 1px solid var(--cds-border);
  font-size: 10px;
  color: var(--cds-text-2);
  text-align: center;
}

@media print {
  .no-print { display: none !important; }
  html, body { background: #fff; }
  .app-main { max-width: none; padding: 0; margin: 0; }
  .card { border: none; padding: 0; margin: 0; }
  .inv-sheet-wrap { background: none; padding: 0; }
  .inv-sheet {
    width: auto;
    box-shadow: none;
    border: none;
    margin: 0;
  }
  @page { size: A4; margin: 0; }
}
