:root {
  --primary-color: #113a55;
  --primary-dark: #b39400;
  --secondary-color: #f0f4f8;
  --text-dark: #2c3e50;
  --text-light: #7f8c8d;
  --border-color: #ecf0f1;
  --success-color: #27ae60;
  --danger-color: #e74c3c;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
}

body {
  font-family: 'Cairo', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  direction: rtl;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  padding: 20px;
  overflow-x: hidden;
}

.main-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  max-width: 1600px;
  margin: 0 auto;
}

.main-container.single-pane {
  grid-template-columns: 1fr;
  max-width: 900px;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(3px);
  z-index: 9999;
  min-height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.app-locked .auth-overlay {
  display: flex;
}

body.app-locked {
  overflow: hidden;
}

body.app-locked .main-container {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

.auth-card {
  width: min(420px, 100%);
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid #e6eaf0;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
}

.auth-title {
  margin: 0 0 8px;
  color: var(--text-dark);
  font-size: 24px;
  font-weight: 800;
}

.auth-subtitle {
  margin: 0 0 18px;
  color: var(--text-light);
  line-height: 1.6;
}

.auth-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.auth-input {
  width: 100%;
  border: 2px solid var(--border-color);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  min-height: 48px;
  direction: ltr;
  text-align: left;
}

.auth-input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(212, 168, 0, 0.14);
}

.auth-submit {
  border: none;
  border-radius: 10px;
  background: var(--primary-color);
  color: #fff;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.2s ease;
  min-height: 48px;
}

.auth-submit:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.auth-submit:disabled {
  background: #bfc5d1;
  cursor: not-allowed;
  transform: none;
}

.auth-attempts {
  margin: 12px 0 0;
  color: var(--text-light);
  font-size: 13px;
}

.auth-error {
  display: none;
  margin: 8px 0 0;
  color: #c0392b;
  font-weight: 700;
  font-size: 13px;
}

/* Editor Section */
.editor-section {
  display: flex;
  flex-direction: column;
}

.editor-card {
  background: white;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  animation: slideInLeft 0.5s ease;
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.section-title {
  color: var(--text-dark);
  font-size: 18px;
  font-weight: 600;
  margin: 20px 0 15px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--primary-color);
}

.section-title:first-child {
  margin-top: 0;
}

/* Form Styling */
.form-group {
  margin-bottom: 20px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 15px;
}

.amounts-row {
  grid-template-columns: 1fr 1fr;
}

.form-input {
  display: flex;
  flex-direction: column;
}

.form-input.full-width {
  grid-column: 1 / -1;
}

.form-input label {
  color: var(--text-dark);
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 14px;
}

.form-input input,
.form-input select {
  padding: 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.3s ease;
  font-family: inherit;
}

.form-input textarea {
  padding: 12px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 14px;
  transition: all 0.3s ease;
  font-family: inherit;
  resize: vertical;
  min-height: 84px;
}

.form-input input:focus,
.form-input select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(212, 168, 0, 0.1);
}

.form-input textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(212, 168, 0, 0.1);
}

.form-input input::placeholder {
  color: var(--text-light);
}

.form-input textarea::placeholder {
  color: var(--text-light);
}

/* Table Styling */
.table-container {
  overflow-x: auto;
  margin: 15px 0;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.edit-table thead {
  background: var(--primary-color);
}

.invoice-table thead {
  background: var(--primary-color);
}

table thead th {
  padding: 12px;
  color: white;
  font-weight: 600;
  text-align: center;
}

table tbody td {
  padding: 10px;
  border-bottom: 1px solid var(--border-color);
  text-align: center;
  background: white;
}

.edit-table tbody input,
.edit-table tbody select {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 13px;
  text-align: center;
  font-family: inherit;
  background: #fff;
}

.edit-table tbody input:focus,
.edit-table tbody select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 2px rgba(212, 168, 0, 0.1);
}

.edit-table tbody button {
  background: var(--danger-color);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  transition: all 0.3s ease;
}

.edit-table tbody button:hover {
  background: #c0392b;
  transform: scale(1.05);
}

/* Button Styling */
.btn-add {
  background: var(--success-color);
  color: white;
  border: none;
  padding: 12px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  margin: 15px 0;
  transition: all 0.3s ease;
  width: 100%;
}

.btn-add:hover {
  background: #229954;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(39, 174, 96, 0.3);
}

.button-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.btn-primary,
.btn-secondary {
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.3s ease;
  text-align: center;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(212, 168, 0, 0.3);
}

.btn-secondary {
  background: #3498db;
  color: white;
}

.btn-secondary:hover {
  background: #2980b9;
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(52, 152, 219, 0.3);
}

.btn-secondary:disabled { opacity: .65; cursor: wait; transform: none; }
.pdf-status { min-height: 20px; margin-top: 8px; color: #173c5e; font-size: 13px; text-align: center; }
.pdf-status.error { color: #b42318; }

/* Preview Section */
.preview-section {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.preview-section.preview-hidden {
  position: fixed;
  top: 0;
  left: 0;
  width: 210mm;
  z-index: -1;
  pointer-events: none;
  transform: translateX(calc(-100% - 24px));
}

.invoice-preview {
  background: white;
  border-radius: 0;
  padding: 8mm 8mm 6mm;
  box-shadow: none;
  animation: none;
  font-size: 13px;
  width: 210mm;
  max-width: 100%;
  min-height: 297mm;
  margin: 0;
}

.invoice-preview::before {
  content: '';
  display: block;
  height: 2mm;
  background: var(--primary-color);
  margin-bottom: 10mm;
}

.invoice-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
  direction: ltr;
}

.company-info {
  flex: 1;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}

.company-logo {
  width: 5cm;
  max-width: 100%;
  height: auto;
  margin-bottom: 0;
  object-fit: contain;
}

.company-name {
  color: var(--primary-color);
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 2px;
}

.company-slogan {
  color: var(--text-light);
  font-size: 12px;
  font-style: italic;
}

.invoice-info {
  text-align: right;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-end;
  min-width: 40mm;
  direction: rtl;
}

.invoice-info p {
  color: var(--text-dark);
  font-weight: 600;
  width: 100%;
  text-align: right;
  direction: rtl;
}

.invoice-divider {
  height: 2px;
  background: linear-gradient(90deg, var(--primary-color), transparent);
  margin: 10px 0;
}

.client-info {
  margin-bottom: 15px;
}

.client-info .label {
  color: var(--text-dark);
  font-weight: 600;
  font-size: 12px;
}

.client-info .value {
  color: var(--text-dark);
  font-size: 16px;
  font-weight: 700;
  margin-top: 5px;
}

.invoice-table {
  margin: 15px 0;
}

.invoice-table tbody tr {
  background: var(--secondary-color);
}

.invoice-table tbody tr:hover {
  background: #e8ecf1;
}

.invoice-table tbody tr:last-child td {
  border-bottom: none;
}

.note-section {
  display: none;
  margin: 12px 0 14px;
  padding: 12px 14px;
  border-radius: 8px;
  border-right: 4px solid var(--primary-color);
  background: #fff8e3;
}

.note-label {
  color: var(--text-dark);
  font-weight: 700;
  margin-bottom: 4px;
}

.note-text {
  color: var(--text-dark);
  line-height: 1.6;
  white-space: pre-wrap;
}

.empty-state {
  text-align: center;
  color: var(--text-light);
  font-style: italic;
  padding: 20px !important;
}

/* Summary Section */
.summary-section {
  background: var(--secondary-color);
  padding: 20px;
  border-radius: 8px;
  border-right: 4px solid var(--primary-color);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  font-weight: 600;
  color: var(--text-dark);
}

.summary-row.highlight {
  font-size: 16px;
  padding: 12px;
  background: var(--primary-color);
  color: white;
  border-radius: 4px;
  margin-top: 10px;
}

.summary-row .label {
  font-size: 13px;
}

.summary-row .value {
  font-size: 14px;
}

.summary-row.highlight .value {
  font-size: 18px;
}

/* Invoice Footer */
.invoice-footer {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--border-color);
  break-inside: avoid;
}

.invoice-footer > p:not(.footer-note) {
  display: none;
}

.footer-note {
  text-align: center;
  color: var(--text-dark);
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 10px;
}

.footer-approvals {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8mm;
  align-items: start;
  direction: rtl;
  justify-items: end;
}

.footer-approvals.single-approval {
  grid-template-columns: 1fr;
  gap: 0;
  justify-items: end;
}

.footer-approval {
  color: var(--text-dark);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  text-align: right;
  justify-self: end;
  min-width: 58mm;
}

.footer-title {
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 4px;
  width: 100%;
  text-align: right;
}

.footer-sign-label {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 2px;
  width: 100%;
  text-align: right;
}

.footer-signature {
  color: #1f6feb;
  font-size: 18px;
  font-family: "Segoe Script", "Bradley Hand ITC", cursive;
  line-height: 1;
  min-height: 18px;
  transform: rotate(-4deg);
  width: 100%;
  text-align: right;
}

.left-approval {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.footer-stamp {
  width: calc(190px + 1cm);
  height: calc(190px + 1cm);
  margin-top: -3cm;
  margin-right: 0.8cm;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  align-self: flex-end;
}

.footer-stamp img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transform: rotate(-6deg);
  transform-origin: center;
  filter: contrast(1.08) saturate(1.1);
}

/* Responsive Design */
@media (max-width: 1200px) {
  .main-container {
    grid-template-columns: 1fr;
  }
  
  .form-row {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  body {
    padding: 8px;
  }

  .auth-overlay {
    align-items: flex-start;
    padding: calc(env(safe-area-inset-top, 0px) + 12px) 12px 12px;
  }

  .auth-card {
    padding: 18px;
    border-radius: 14px;
    width: 100%;
    max-height: calc(100dvh - 24px);
  }

  .auth-title {
    font-size: 21px;
  }

  .auth-subtitle {
    font-size: 14px;
    margin-bottom: 14px;
  }

  .auth-form {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .auth-submit {
    width: 100%;
  }

  body.app-locked .main-container {
    filter: none;
  }

  .main-container.single-pane {
    max-width: 100%;
  }
  
  .editor-card,
  .invoice-preview {
    padding: 14px;
    border-radius: 10px;
  }

  .section-title {
    font-size: 16px;
    margin: 14px 0 10px;
  }

  .form-input input,
  .form-input select,
  .form-input textarea {
    font-size: 16px;
  }
  
  .form-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .table-container {
    margin: 10px 0;
  }

  table {
    font-size: 13px;
  }
  
  .button-group {
    grid-template-columns: 1fr;
  }

  .btn-primary,
  .btn-secondary,
  .btn-add {
    font-size: 15px;
    padding: 12px 14px;
  }

  .invoice-header {
    flex-direction: column;
    text-align: right;
    direction: rtl;
  }
  
  .company-info {
    justify-content: center;
  }

  .invoice-info {
    margin-top: 10px;
    text-align: right;
    align-items: flex-end;
    min-width: auto;
  }

  .company-logo {
    width: 5cm;
  }

  .footer-note {
    font-size: 18px;
  }

  .footer-approvals {
    grid-template-columns: 1fr;
    gap: 14px;
    justify-items: end;
  }

  .footer-title {
    font-size: 17px;
  }

  .footer-sign-label {
    font-size: 15px;
  }

  .footer-signature {
    font-size: 21px;
  }

  .left-approval {
    align-items: flex-end;
  }

  .footer-stamp {
    width: 130px;
    height: 130px;
    font-size: 15px;
  }
}

@media (max-width: 640px) {
  .table-container {
    overflow: visible;
    border: 0;
  }

  .edit-table thead {
    display: none;
  }

  .edit-table,
  .edit-table tbody,
  .edit-table tr,
  .edit-table td {
    display: block;
    width: 100%;
  }

  .edit-table tbody tr {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 10px;
  }

  .edit-table tbody td {
    display: grid;
    grid-template-columns: 88px 1fr;
    gap: 10px;
    align-items: center;
    text-align: right;
    padding: 7px 0;
    border-bottom: 1px dashed var(--border-color);
  }

  .edit-table tbody td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .edit-table tbody td::before {
    font-weight: 700;
    color: var(--text-dark);
    text-align: right;
  }

  .edit-table tbody td:nth-child(1)::before { content: "\0627\0644\0628\064A\0627\0646"; }
  .edit-table tbody td:nth-child(2)::before { content: "\0627\0644\0639\062F\062F"; }
  .edit-table tbody td:nth-child(3)::before { content: "\0627\0644\0645\0642\0627\0633"; }
  .edit-table tbody td:nth-child(4)::before { content: "\0627\0644\0648\062D\062F\0629"; }
  .edit-table tbody td:nth-child(5)::before { content: "\0633\0639\0631\0020\0627\0644\0648\062D\062F\0629"; }
  .edit-table tbody td:nth-child(6)::before { content: "\0627\0644\0645\062C\0645\0648\0639"; }
  .edit-table tbody td:nth-child(7)::before { content: "\062D\0630\0641"; }

  .edit-table tbody input,
  .edit-table tbody select {
    font-size: 16px;
    text-align: right;
  }

  .edit-table tbody td:nth-child(6) {
    font-weight: 700;
    color: var(--text-dark);
  }

  .edit-table tbody td:nth-child(7) button {
    width: 100%;
    padding: 10px;
    font-size: 14px;
  }
}

/* Print Styles */
@page {
  size: A4;
  margin: 8mm;
}

@media print {
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  body {
    background: white;
    padding: 0;
    margin: 0;
  }
  
  .main-container {
    display: block;
    max-width: none;
    margin: 0;
    gap: 0;
  }
  
  .editor-section {
    display: none;
  }
  
  .preview-section {
    display: block;
    width: 100%;
    margin: 0;
    padding: 0;
  }
  
  .invoice-preview {
    box-shadow: none;
    border-radius: 0;
    padding: 8mm 8mm 6mm;
    max-width: 100%;
    margin: 0;
  }

  .invoice-header {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0;
    direction: ltr;
  }

  .company-info {
    display: flex;
    justify-content: flex-start;
    align-items: center;
  }

  .company-logo {
    width: 5cm;
    margin-bottom: 0;
  }

  .invoice-info {
    text-align: right;
    align-items: flex-end;
    gap: 2px;
    min-width: 40mm;
    margin-top: 0;
    direction: rtl;
  }

  .invoice-divider {
    margin: 10px 0;
  }

  .invoice-table thead th,
  .summary-row.highlight {
    background: var(--primary-color) !important;
    color: #fff !important;
  }

  .invoice-footer {
    margin-top: 12px;
    padding-top: 10px;
    break-inside: auto;
    page-break-inside: auto;
  }

  .footer-approvals {
    grid-template-columns: 1fr 1fr;
    gap: 8mm;
    align-items: start;
    direction: rtl;
    justify-items: end;
  }

  .footer-approval {
    text-align: right;
    justify-self: end;
    min-width: 58mm;
  }

  .left-approval {
    align-items: flex-end;
  }

  .footer-note {
    font-size: 18px;
    margin-bottom: 10px;
  }

  .footer-title {
    font-size: 16px;
    margin-bottom: 4px;
  }

  .footer-sign-label {
    font-size: 14px;
    margin-bottom: 2px;
  }

  .footer-signature {
    font-size: 18px;
    min-height: 18px;
  }

  .footer-stamp {
    width: calc(180px + 1cm);
    height: calc(180px + 1cm);
    margin-top: -3cm;
    margin-right: 0.8cm;
  }
  
  .invoice-preview::before {
    content: '';
    display: block;
    height: 2mm;
    background: var(--primary-color);
    margin-bottom: 10mm;
  }
}

/* A4 invoice artwork */
.preview-section .invoice-preview {
  position: relative;
  width: 210mm;
  min-height: 297mm;
  max-width: none;
  padding: 0 7.5mm 8mm;
  overflow: hidden;
  color: #173c5e;
  background: #fff;
  font-family: 'Cairo', 'Segoe UI', sans-serif;
  font-size: 11px;
}

.preview-section .invoice-preview::before {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1.5px;
  margin: 0;
  background: #1d689a;
}

.corner-ribbon-left {
  position: absolute;
  top: -17px;
  left: 0;
  width: 100px;
  height: 90px;
  opacity: .65;
  background: repeating-linear-gradient(135deg, transparent 0 15px, #deedf7 16px 27px, transparent 28px 38px);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

.preview-section .invoice-header {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 166px;
  margin: 0;
  direction: ltr;
}

.preview-section .company-info {
  flex: none;
  width: 43%;
  align-self: center;
  justify-content: flex-start;
  padding-left: 10px;
}

.preview-section .company-logo {
  width: 204px;
  height: auto;
  max-height: 112px;
  object-fit: contain;
}

.header-separator {
  align-self: stretch;
  flex: none;
  width: 1px;
  height: 112px;
  margin: auto 0;
  background: #2c82b3;
}

.preview-section .invoice-info {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 0;
  align-items: stretch;
  gap: 1px;
  padding: 0 135px 0 48px;
  direction: rtl;
  text-align: right;
}

.invoice-info h1 {
  margin: -5px 0 5px;
  font-size: 30px;
  line-height: 1.5;
  font-weight: 800;
  color: #073c61;
}

.preview-section .invoice-info p {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 5px;
  width: 190px;
  font-size: 12px;
  white-space: nowrap;
  color: #23486a;
}

.invoice-info p strong { font-weight: 800; }
.invoice-info p span { direction: ltr; text-align: left; font-weight: 600; }

.header-art {
  position: absolute;
  top: 0;
  right: -7.5mm;
  width: 149px;
  height: 166px;
  overflow: hidden;
  border-bottom-left-radius: 60px 40px;
  background: #00385d url('./header-led-buildings.png') center 43% / cover no-repeat;
  clip-path: polygon(33% 0, 100% 0, 100% 100%, 34% 100%, 0 77%, 0 20%);
}

.header-art::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(145deg, rgba(12,70,112,.15), transparent 50%);
}

.preview-section .invoice-divider {
  height: 1px;
  margin: 0 0 13px;
  background: #9cc8e2;
}

.preview-section .invoice-table {
  table-layout: fixed;
  width: 100%;
  margin: 0 0 29px;
  border: 1px solid #dce9f2;
  border-radius: 6px;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  direction: rtl;
  color: #1a3755;
  font-family: Arial, 'Cairo', sans-serif;
  font-size: 11px;
}

.invoice-table th:nth-child(1) { width: 6%; }
.invoice-table th:nth-child(2) { width: 32%; }
.invoice-table th:nth-child(3) { width: 11%; }
.invoice-table th:nth-child(4) { width: 9%; }
.invoice-table th:nth-child(5) { width: 11%; }
.invoice-table th:nth-child(6) { width: 15%; }
.invoice-table th:nth-child(7) { width: 16%; }

.preview-section .invoice-table thead { background: #073c5e; }
.preview-section .invoice-table thead th {
  height: 39px;
  padding: 5px 3px;
  border-left: 1px solid rgba(255,255,255,.25);
  background: linear-gradient(110deg, #0c4a70, #083c5c);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.preview-section .invoice-table tbody td {
  height: 29.6px;
  padding: 3px 5px;
  border-left: 1px solid #e0ebf2;
  border-bottom: 1px solid #e5edf2;
  background: #fff;
  color: #1a3553;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: ltr;
  font-weight: 400;
}

.preview-section .invoice-table tbody tr:nth-child(even) td { background: #edf5fa; }
.preview-section .invoice-table tbody tr:hover td { background: inherit; }
.preview-section .invoice-table tbody td:last-child,
.preview-section .invoice-table thead th:last-child { border-left: 0; }
.preview-section .invoice-table tbody tr:last-child td { border-bottom: 0; }
.preview-section .invoice-table .empty-state { height: 580px; }

.preview-section .summary-section {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 9px;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  direction: rtl;
}

.preview-section .summary-row,
.preview-section .summary-row.highlight {
  display: grid !important;
  grid-template-columns: 28px minmax(0,1fr);
  grid-template-rows: 26px 27px;
  align-content: center;
  gap: 0 4px;
  min-height: 63px;
  margin: 0;
  padding: 5px 7px;
  border: 0;
  border-radius: 7px;
  background: #eef5fa;
  color: #143c61;
  box-shadow: none;
}

.preview-section .summary-row.summary-total {
  background: linear-gradient(120deg, #0a4269, #073559);
  color: #fff;
}

.preview-section .summary-row.highlight {
  background: linear-gradient(120deg, #1377bd, #0964aa);
  color: #fff;
}

.summary-icon {
  grid-row: 1 / 3;
  align-self: center;
  font-family: Arial, sans-serif;
  font-size: 27px;
  font-weight: 400;
  line-height: 1;
  text-align: center;
}

.preview-section .summary-row .label,
.preview-section .summary-row .value,
.preview-section .summary-row.highlight .value {
  grid-column: 2;
  width: 100%;
  text-align: right;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 700;
}

.preview-section .summary-row .value,
.preview-section .summary-row.highlight .value { font-family: Arial, sans-serif; font-size: 12px; font-weight: 800; }

.preview-section .invoice-footer {
  display: grid;
  grid-template-columns: 25% 41% 30%;
  justify-content: space-between;
  direction: rtl;
  position: relative;
  min-height: 150px;
  margin-top: 18px;
  padding-top: 22px;
  border-top: 1px solid #c6dce9;
  color: #173c5d;
  break-inside: avoid;
}

.footer-notes,
.footer-approval,
.footer-company { min-width: 0; }

.footer-notes { text-align: right; }
.footer-notes h2,
.footer-company h2 {
  margin: 0 0 7px;
  font-size: 12px;
  line-height: 1.5;
  color: #113f63;
  font-weight: 800;
}
.footer-notes p { margin: 0 0 3px; font-size: 9px; line-height: 1.5; white-space: pre-wrap; }

.preview-section .footer-approval {
  position: relative;
  display: block;
  justify-self: stretch;
  min-width: 0;
  height: 110px;
  padding: 0 18px;
  border-right: 1px solid #3b83b1;
  border-left: 1px solid #3b83b1;
  text-align: right;
}

.preview-section .footer-note {
  margin: 0 0 5px;
  color: #778b99;
  font-size: 13px;
  font-weight: 400;
  text-align: center;
  white-space: nowrap;
}
.preview-section .footer-sign-label { margin: 2px 0; font-size: 12px; font-weight: 600; }
.preview-section .footer-stamp {
  position: absolute;
  z-index: 1;
  top: -35px;
  left: 48%;
  width: 205px;
  height: 205px;
  margin: 0;
  transform: translateX(-50%);
  opacity: .86;
}
.preview-section .footer-stamp img { transform: rotate(-6deg); filter: saturate(.9); }

.footer-company {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: right;
  font-family: Arial, 'Cairo', sans-serif;
}
.footer-company h2 { font-family: 'Cairo', sans-serif; }
.footer-company strong { font-size: 10px; }
.footer-company span { font-size: 8px; }
.footer-company p {
  max-width: 100%;
  margin: 2px 0 0;
  font-family: 'Cairo', Arial, sans-serif;
  font-size: 9px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.footer-company p b { font-family: Arial, sans-serif; font-weight: 700; }

@media print {
  @page { size: A4; margin: 0; }
  .preview-section.preview-hidden { position: static; transform: none; }
  .preview-section .invoice-preview { padding: 0 7.5mm 8mm; }
}

/* Mobile invoice workflow and local history */
.invoice-mobile-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.invoice-mobile-nav button {
  min-height: 44px;
  padding: 8px 14px;
  border: 0;
  border-radius: 10px;
  background: #0c527f;
  color: #fff;
  font: 700 13px 'Cairo', sans-serif;
  cursor: pointer;
}
.invoice-mobile-nav strong { color: #0c527f; font: 800 17px Arial, sans-serif; direction: ltr; }
.invoice-quickbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
  padding: 13px 15px;
  border: 1px solid #cfe4f2;
  border-radius: 12px;
  background: #eff7fc;
  color: #143c5b;
}
.invoice-quickbar > div { display: flex; flex-direction: column; line-height: 1.35; }
.invoice-quickbar span { font-size: 12px; }
.invoice-quickbar strong { font-family: Arial, sans-serif; font-size: 20px; direction: ltr; text-align: right; }
.invoice-quickbar small { font-size: 11px; color: #56758b; }
.btn-new {
  min-height: 42px;
  padding: 8px 14px;
  border: 1px solid #0d659e;
  border-radius: 9px;
  background: #fff;
  color: #0b5688;
  font: 700 13px 'Cairo', sans-serif;
  cursor: pointer;
}
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 8000;
  background: rgba(7, 30, 48, .5);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}
.invoice-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 8001;
  display: flex;
  flex-direction: column;
  width: min(370px, 90vw);
  height: 100dvh;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  background: #fff;
  box-shadow: -10px 0 35px rgba(7, 37, 59, .2);
  transform: translateX(105%);
  transition: transform .22s ease;
  direction: rtl;
}
body.sidebar-open { overflow: hidden; }
body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
body.sidebar-open .invoice-sidebar { transform: translateX(0); }
.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 15px;
  border-bottom: 1px solid #d9e8f1;
}
.sidebar-heading span { color: #1680bd; font: 800 12px Arial, sans-serif; }
.sidebar-heading h2 { margin: 3px 0 0; color: #0b4166; font-size: 20px; }
.sidebar-heading button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: #edf5fa;
  color: #124c73;
  font: 28px Arial, sans-serif;
  cursor: pointer;
}
.sidebar-section { padding: 18px 0; border-bottom: 1px solid #e1ecf3; }
.sidebar-section h3 { margin: 0 0 5px; color: #123e5d; font-size: 15px; }
.sidebar-section h3 span { padding: 0 7px; border-radius: 20px; background: #dceefa; }
.sidebar-section p { margin: 0 0 13px; color: #607f94; font-size: 12px; line-height: 1.6; }
.currency-options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.currency-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80px;
  padding: 10px;
  border: 2px solid #cfe1ec;
  border-radius: 12px;
  background: #f7fafc;
  color: #194b6c;
  font-family: 'Cairo', sans-serif;
  cursor: pointer;
}
.currency-option strong { font-size: 13px; white-space: nowrap; }
.currency-option span { font: 800 16px Arial, sans-serif; }
.currency-option.selected { border-color: #0b70ad; background: #e9f5fc; box-shadow: inset 0 0 0 1px #0b70ad; }
.currency-option:focus-visible,
.invoice-mobile-nav button:focus-visible,
.sidebar-heading button:focus-visible { outline: 3px solid #f2b51a; outline-offset: 2px; }
.currency-native { display: none; }
.sidebar-history label { display: block; margin-bottom: 6px; color: #294a63; font-size: 13px; font-weight: 700; }
.sidebar-history input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid #bdd5e4;
  border-radius: 8px;
  outline-color: #0d659e;
  font: 14px 'Cairo', sans-serif;
  direction: rtl;
}
.history-list { display: grid; gap: 9px; margin-top: 12px; }
.history-empty { padding: 14px; border-radius: 8px; background: #f6f9fb; color: #6b7e8c; font-size: 13px; text-align: center; }
.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 12px;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid #dbe8f0;
  border-radius: 10px;
  background: #fff;
}
.history-item strong { color: #104a70; font: 800 16px Arial, sans-serif; direction: ltr; text-align: right; }
.history-item .history-client { color: #273e50; font-size: 13px; font-weight: 700; overflow-wrap: anywhere; }
.history-item .history-meta { color: #607a8d; font-size: 11px; }
.history-item button {
  grid-column: 2;
  grid-row: 1 / 5;
  min-height: 40px;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: #0d679f;
  color: #fff;
  font: 700 12px 'Cairo', sans-serif;
  cursor: pointer;
}
.invoice-save-status { min-height: 21px; margin-top: 14px; color: #176040; font-size: 13px; text-align: center; }
.invoice-save-status.error { color: #b42318; }

@media (max-width: 640px) {
  .invoice-quickbar { padding: 11px; }
  .button-group {
    position: sticky;
    bottom: 0;
    z-index: 20;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0 -14px -14px;
    padding: 9px 14px calc(9px + env(safe-area-inset-bottom, 0px));
    background: #fff;
    box-shadow: 0 -6px 22px rgba(15, 56, 84, .1);
  }
  .button-group button { min-height: 44px; padding: 8px 5px; font-size: 13px; }
}
