@font-face {
  font-family: 'Ghaith Sans';
  src: url('fonts/ArbFONTS-GHAITHSANS-Regular.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --ink: #0f2942;
  --text: #000;
  --paper: #fff;
  --canvas: #f5f5f5;
  --secondary: #e2e8f0;
  --line: #333;
  --gold: #b9985a;
  --muted: #626972;
  --danger: #a12b2b;
}

* { box-sizing: border-box; }
body { margin: 0; padding: 15px; background: var(--canvas); color: var(--text); font: 13px Arial, 'Ghaith Sans', sans-serif; }
button, input, a { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button, a.btn { cursor: pointer; }
button, a, input { transition: background-color 150ms, border-color 150ms, box-shadow 150ms; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
input { min-width: 0; color: var(--text); background: var(--paper); font-family: inherit; }
input::placeholder { color: #727272; opacity: 1; }
input:user-invalid { border-color: var(--danger); }
input[type='number'] { appearance: textfield; -moz-appearance: textfield; }
input::-webkit-inner-spin-button, input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input:focus-visible { outline-offset: 1px; }
[hidden] { display: none !important; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip-link:focus { position: fixed; top: 8px; left: 8px; z-index: 10; padding: 12px; background: white; color: var(--ink); }
.print-value { display: none; }
html[data-auth-pending] body { visibility: hidden; }
button:disabled { opacity: .65; cursor: wait; }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 24px; }
.login-card { width: 380px; max-width: 100%; padding: 40px 36px; border: 1px solid rgba(226,232,240,.8); border-radius: 12px; background: white; box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.login-logo { display: block; width: 84px; height: 71px; object-fit: contain; margin: 0 auto 18px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; color: var(--ink); text-align: center; }
.login-subtitle { margin: 0 0 28px; color: #64748b; font-size: 12px; text-align: center; }
.login-field { margin-bottom: 16px; }
.login-field label { display: block; margin-bottom: 6px; color: #536276; font-size: 11px; font-weight: 600; }
.login-field input { display: block; width: 100%; padding: 10px 12px; border: 1px solid var(--secondary); border-radius: 8px; font-size: 14px; }
.login-field input:hover { border-color: #b9c4d1; }
.login-error { min-height: 18px; margin: 0 0 12px; color: var(--danger); font-size: 12px; line-height: 1.5; }
.btn-login { width: 100%; min-height: 42px; padding: 12px; font-size: 15px; }
@media screen and (max-width: 480px) {
  .login-page { padding: 20px; }
  .login-card { padding: 32px 24px; }
  .login-field input { min-height: 44px; font-size: 16px; }
  .login-field label { font-size: 12px; }
}

.invoice-page { width: 100%; max-width: 880px; margin: 0 auto; padding: 44px 56px; border: 1px solid rgba(226,232,240,.8); border-radius: 12px; background: var(--paper); box-shadow: 0 2px 8px rgba(15,41,66,.06), 0 24px 48px -12px rgba(0,0,0,.1); }
.invoice-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 32px; padding-bottom: 20px; border-bottom: 1px solid #e5e7eb; }
.btn { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 8px; padding: 10px 20px; font: 600 13px Arial, sans-serif; line-height: 15px; text-decoration: none; }
.btn-print { background: var(--ink); color: white; }
.btn-print:hover { background: #1f405d; }
.btn-back { background: var(--secondary); color: #1a1a1a; }
.btn-back:hover { background: #cfd8e4; }
.btn:active { box-shadow: inset 0 1px 4px #0003; }
.company-name-top { margin: 0 0 12px; text-align: center; font-size: 16px; font-weight: 700; color: var(--ink); }
.header-row { display: flex; align-items: center; justify-content: space-between; height: 52px; }
.header-row h1 { margin: 0; color: var(--ink); font-size: 18px; font-weight: 700; }
.invoice-logo { display: block; width: 100px; height: 59px; object-fit: contain; }
.header-line { height: 2px; margin: 16px 0 24px; background: var(--ink); }
.invoice-body-purchase { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 24px; margin-bottom: 20px; }
.invoice-body-purchase h2 { margin: 0 0 12px; font-size: 13px; letter-spacing: .5px; }
.invoice-meta-row { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; margin-bottom: 16px; }
.meta-item { display: flex; align-items: center; gap: 10px; width: 100%; }
.meta-label { flex: 0 0 140px; font-size: 13px; font-weight: 600; }
.meta-input-inline { width: 100%; border: 1px solid var(--line); border-radius: 4px; padding: 8px 12px; font-size: 15px; font-weight: 500; }
.company-info { font-size: 14px; font-weight: 500; line-height: 23.8px; }
.company-info input { display: block; width: 100%; height: 23.8px; border: 1px solid transparent; border-radius: 3px; padding: 0; font: inherit; line-height: inherit; }
.company-info input:hover, .company-info input:focus { border-color: #b5bdc6; }
.field { margin-bottom: 10px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; margin-bottom: 6px; font-size: 12px; font-weight: 600; letter-spacing: .36px; text-transform: uppercase; }
.field input { width: 100%; border: 1px solid var(--line); border-radius: 4px; padding: 8px 12px; font-size: 15px; }

.invoice-table-wrap { margin-bottom: 20px; }
table { border-collapse: collapse; }
.invoice-table { width: 100%; table-layout: fixed; border: 1px solid var(--line); font-size: 15px; }
.col-price, .col-amount { width: 100px; }
.col-qty { width: 70px; }
.invoice-table th { padding: 10px 14px; border: 1px solid #555; background: var(--line); color: white; font-size: 11px; font-weight: 600; text-transform: uppercase; }
.invoice-table th:first-child { text-align: left; }
.invoice-table th:last-child { text-align: right; }
.invoice-table td { padding: 10px 14px; border: 1px solid #888; font-weight: 500; overflow-wrap: anywhere; }
.invoice-table input { width: 100%; padding: 6px 10px; border: 1px solid #888; border-radius: 0; font-size: 14px; font-weight: 500; }
.description-cell { position: relative; }
.invoice-table .item-desc { padding-right: 24px; }
.remove-row { position: absolute; top: 50%; right: 16px; transform: translateY(-50%); width: 22px; height: 27px; padding: 0; border: 0; background: var(--paper); color: var(--danger); font-size: 20px; opacity: 0; }
.description-cell:hover .remove-row, .description-cell:focus-within .remove-row { opacity: 1; }
.remove-row:hover { background: #fcecec; }
.invoice-table tbody tr:only-child .remove-row { display: none; }
.amount-cell { font-variant-numeric: tabular-nums; }
.add-row { position: relative; margin-top: 8px; padding: 0; border: 1px solid #8a8a8a; border-radius: 0; background: var(--secondary); color: #1a1a1a; font: 13px Arial, sans-serif; line-height: 17px; }
.add-row:hover { background: #cfd8e4; }
.add-row::after { content: ''; position: absolute; inset: -5px -6px; }
.totals-table { width: 300px; max-width: 100%; margin: 0 0 24px auto; border: 1px solid var(--line); font-size: 13px; font-variant-numeric: tabular-nums; }
.totals-table th, .totals-table td { border: 1px solid #999; padding: 6px 12px; }
.totals-table th { width: 41%; text-align: left; font-weight: 600; }
.totals-table td { text-align: right; overflow-wrap: anywhere; }
.totals-table input { width: 65px; border: 1px solid var(--secondary); border-radius: 4px; padding: 2px 6px; text-align: right; font-size: 13px; }
.total-row { background: #f5f7fa; color: var(--ink); font-size: 14px; font-weight: 700; }
.total-row th { font-weight: 700; }
.invoice-footer { display: flex; justify-content: center; margin-top: 36px; padding-top: 24px; }
.invoice-seal { display: block; width: 256px; max-width: 100%; height: 258px; object-fit: contain; }
.form-feedback { margin: 12px 0 0; color: var(--danger); text-align: right; line-height: 1.6; }

dialog { max-width: min(440px,calc(100% - 32px)); border: 1px solid var(--secondary); border-radius: 12px; padding: 28px; color: var(--ink); box-shadow: 0 20px 80px #0002; }
dialog::backdrop { background: #0f294266; }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
dialog p { margin: 0 0 24px; color: #495564; font-size: 14px; line-height: 1.7; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.home-page { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.home-card { width: 100%; max-width: 470px; border: 1px solid var(--secondary); border-radius: 12px; padding: 44px; background: white; box-shadow: 0 12px 40px #0f29420d; text-align: center; }
.home-logo { width: 150px; height: auto; margin-bottom: 24px; }
.home-card h1 { margin: 0 0 12px; color: var(--ink); font-size: 23px; }
.home-card p { color: var(--muted); line-height: 1.7; }
.home-card .btn { margin-top: 12px; }
.home-card .local-notice { margin: 24px 0 0; font-size: 12px; }

@media screen and (max-width: 800px) {
  .invoice-page { padding: 32px; }
  .meta-label { flex-basis: 112px; }
  .invoice-body-purchase { gap: 20px; }
  .meta-input-inline { padding-left: 8px; padding-right: 8px; font-size: 14px; }
  .col-price, .col-amount { width: 95px; }
  .col-qty { width: 65px; }
  .invoice-table th, .invoice-table td { padding-left: 10px; padding-right: 10px; }
}

@media screen and (max-width: 600px) {
  body { padding: 10px; }
  .invoice-page { padding: 24px 20px; border-radius: 8px; }
  .invoice-actions { gap: 8px; margin-bottom: 28px; }
  .btn { min-height: 44px; padding: 10px 16px; }
  .header-row { height: 64px; gap: 16px; }
  .header-row h1 { font-size: 16px; }
  .invoice-logo { width: 69px; height: 58px; }
  .invoice-body-purchase { grid-template-columns: 1fr; gap: 28px; }
  .meta-label { flex-basis: 106px; }
  .field input, .meta-input-inline { min-height: 44px; font-size: 16px; }
  .company-info input { height: 36px; font-size: 16px; }
  .invoice-table, .invoice-table tbody { display: block; border: 0; }
  .invoice-table colgroup { display: none; }
  .invoice-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .invoice-table tbody { display: grid; gap: 16px; }
  .invoice-table tr { display: grid; grid-template-columns: minmax(0,1fr) 72px minmax(0,1fr); border: 1px solid #888; }
  .invoice-table td { display: flex; flex-wrap: wrap; align-content: start; align-items: center; gap: 6px; padding: 10px; border: 0; }
  .invoice-table td::before { content: attr(data-label); flex: 0 0 100%; color: var(--ink); font-size: 11px; font-weight: 700; text-transform: uppercase; }
  .invoice-table .description-cell { grid-column: 1 / -1; border-bottom: 1px solid #aaa; }
  .invoice-table input { min-height: 44px; padding: 8px; font-size: 16px; }
  .invoice-table .item-desc { padding-right: 36px; }
  .invoice-table .amount-cell { gap: 4px; align-content: start; }
  .invoice-table .amount-cell::before { margin-bottom: 16px; }
  .remove-row { width: 36px; height: 44px; top: auto; bottom: 10px; right: 11px; transform: none; opacity: 1; }
  .add-row { min-height: 44px; margin-top: 12px; padding: 8px 12px; border-radius: 4px; }
  .add-row::after { display: none; }
  .totals-table { width: 100%; }
  .totals-table input { min-height: 36px; width: 100px; font-size: 16px; }
  .totals-table th, .totals-table td { padding: 10px 12px; }
  .invoice-footer { margin-top: 24px; padding-top: 0; }
  .invoice-seal { height: 224px; }
  .home-card { padding: 32px 24px; }
}

@media (hover: none) { .remove-row { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }

@page { size: A4; margin: 12mm; }
@media print {
  html, body { margin: 0; padding: 0; background: white; }
  body { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .invoice-page { width: 100%; max-width: none; border: 0; border-radius: 0; padding: 0; box-shadow: none; }
  .no-print, .skip-link, dialog, noscript { display: none !important; }
  .invoice-header { break-inside: avoid; }
  .invoice-body-purchase { grid-template-columns: minmax(0,1fr) minmax(0,1fr); break-inside: avoid; }
  input { display: none !important; }
  .print-value { display: inline; white-space: pre-wrap; overflow-wrap: anywhere; }
  .meta-item .print-value { flex: 1; font-size: 14px; }
  .meta-label { flex-basis: 125px; }
  .meta-item { min-height: 28px; }
  .field .print-value { display: block; min-height: 24px; font-size: 15px; }
  .invoice-table { font-size: 13px; }
  .invoice-table th, .invoice-table td { padding: 10px; }
  .invoice-table thead { display: table-header-group; }
  .invoice-table tr { break-inside: avoid; }
  .col-price { width: 105px; }
  .col-amount { width: 120px; }
  .col-qty { width: 55px; }
  .totals-table { break-inside: avoid; }
  .invoice-footer { margin-top: 28px; padding-top: 0; break-inside: avoid; }
  .invoice-seal { height: 200px; }
  .home-page { display: block; }
}
