﻿:root {
  --ink: #111;
  --grid: #3a3a3a;
  --header-bg: #9dbbd3;
  --paper: #fff;
  --sheet: #f1f1f1;
  --gap: 12px;
  --gap-sm: 8px;
}

* {
  box-sizing: border-box;
  font-family: "Cairo", Arial, sans-serif;
}

body {
  margin: 0;
  background: var(--sheet);
  color: var(--ink);
  overflow-x: hidden;
  font-size: clamp(14px, 1.8vw, 16px);
}

.page {
  width: min(100%, 900px);
  min-height: auto;
  padding: 16px;
  margin: 0 auto;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.toolbar {
  display: flex;
  gap: var(--gap);
  align-items: center;
  flex-wrap: wrap;
}

.toolbar button {
  padding: 8px 16px;
  border: 1px solid var(--grid);
  background: #fff;
  cursor: pointer;
  font-weight: 600;
}

.warning {
  font-size: 12px;
  color: #a00;
}

.invoice {
  width: 100%;
  min-height: auto;
  background: var(--paper);
  padding: 16px;
  border: 1px solid #ccc;
}

.invoice-header {
  text-align: center;
  margin-bottom: 6mm;
}

.brand-lines {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 14px;
  font-weight: 600;
}

.header-divider {
  margin-top: 6px;
  border-bottom: 1px solid var(--grid);
}

.title {
  text-align: center;
  margin: 12px 0 16px;
  font-size: clamp(20px, 2.4vw, 24px);
  font-weight: 700;
}

.meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  margin-bottom: 16px;
}

.meta-field {
  display: flex;
  gap: 8px;
  align-items: center;
}

.meta-field input {
  border: 0;
  border-bottom: 1px solid #999;
  outline: none;
  font-size: 14px;
  padding: 2px 4px;
  background: transparent;
  min-width: 140px;
  text-align: center;
}

.supplier {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.fixed-text {
  font-weight: 600;
}

.table-wrap {
  border: 1px solid var(--grid);
  width: 100%;
  overflow: hidden;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: clamp(13px, 1.6vw, 14px);
}

.invoice-table th,
.invoice-table td {
  border: 1px solid var(--grid);
  padding: 6px 6px;
  text-align: center;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.invoice-table thead th {
  background: var(--header-bg);
  font-weight: 700;
}

.invoice-table td input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  text-align: center;
  font-size: 13px;
}

.cell-value {
  display: block;
  text-align: center;
}

.col-item {
  width: 46%;
}

.col-qty,
.col-price,
.col-idx,
.col-total {
  width: 11%;
}

.col-actions {
  width: 10%;
}

.cell-total {
  font-weight: 600;
}

.total-row td {
  background: #fff;
  font-weight: 700;
}

.total-label {
  text-align: center;
}

.total-value {
  background: var(--header-bg);
}

.remove-row {
  padding: 4px 8px;
  border: 1px solid var(--grid);
  background: #fff;
  cursor: pointer;
}

.invoice-footer {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: center;
  font-size: clamp(12px, 1.6vw, 13px);
  font-weight: 600;
}

.print-only {
  display: none;
}

@page {
  size: A4;
  margin: 10mm;
}

@media print {
  body {
    background: #fff;
  }

  .no-print {
    display: none !important;
  }

  .screen-only {
    display: none !important;
  }

  .print-only {
    display: block;
  }

  .page {
    padding: 0;
    width: 210mm;
    min-height: 297mm;
  }

  .invoice {
    border: 0;
    width: 100%;
    min-height: 297mm;
    padding: 12mm;
  }

  .page-break {
    page-break-after: always;
  }

  .invoice-table,
  .invoice-table thead,
  .invoice-table tbody,
  .invoice-table tr,
  .invoice-table td {
    display: table;
    width: auto;
  }

  .invoice-table thead {
    display: table-header-group;
  }

  .invoice-table tbody {
    display: table-row-group;
  }

  .invoice-table tr {
    display: table-row;
  }

  .invoice-table td {
    display: table-cell;
  }
}

@media (max-width: 1024px) {
  .page {
    width: 100%;
  }

  .invoice {
    width: 100%;
  }

  .meta {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .page {
    padding: 12px;
    gap: var(--gap-sm);
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar button {
    width: 100%;
  }

  .meta {
    gap: var(--gap-sm);
  }

  .meta-field,
  .supplier {
    flex-direction: column;
    align-items: flex-start;
  }

  .meta-field input {
    width: 100%;
  }

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

  .invoice-table thead {
    display: none;
  }

  .invoice-table tr {
    border: 1px solid var(--grid);
    margin-bottom: 10px;
    padding: 6px;
  }

  .invoice-table td {
    border: 0;
    padding: 6px 4px;
    display: grid;
    grid-template-columns: 38% 1fr;
    gap: 8px;
    align-items: center;
  }

  .invoice-table td::before {
    content: attr(data-label);
    font-weight: 700;
    white-space: nowrap;
    text-align: right;
  }

  .invoice-table td input {
    text-align: right;
  }

  .cell-value {
    text-align: right;
  }

  .total-row {
    border: 1px solid var(--grid);
  }
}
