:root {
  --bg: #eef1f4;
  --surface: #ffffff;
  --ink: #17212b;
  --muted: #627180;
  --line: #d9e0e6;
  --soft: #f6f8fa;
  --accent: #f47c12;
  --accent-dark: #171a1d;
  --amber: #f47c12;
  --danger: #b42318;
  --shadow: 0 20px 60px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #f4f6f8 0%, #e9edf1 100%);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  max-width: 1680px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 3vw, 3rem);
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 0;
}

.topbar-actions,
.items-heading {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

button,
.import-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.primary-button,
.secondary-button,
.dark-button,
.import-button {
  min-height: 42px;
  padding: 11px 16px;
}

.primary-button {
  color: #fff;
  background: var(--accent);
}

.secondary-button,
.import-button {
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}

.dark-button {
  color: #fff;
  background: var(--ink);
}

.compact {
  min-height: 36px;
  padding: 8px 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(340px, 500px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.editor-panel {
  position: relative;
  z-index: 2;
  display: grid;
  gap: 18px;
  padding: 20px;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.hint {
  max-width: 220px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.9rem;
}

.bill-form {
  display: grid;
  gap: 18px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field-grid > label,
.item-row > label {
  min-width: 0;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: #fff;
  min-width: 0;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.items-heading {
  justify-content: space-between;
}

.items-heading h3 {
  margin-bottom: 0;
}

.items-editor {
  display: grid;
  gap: 10px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px 74px 104px auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--soft);
}

.remove-item-button {
  min-height: 42px;
  margin-top: 24px;
  padding: 9px 12px;
  color: var(--danger);
  background: #fff;
  border: 1px solid #f1c7c2;
}

.saved-panel {
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.storage-note {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #fed7aa;
  border-radius: 8px;
  color: #7c2d12;
  background: #fff7ed;
  font-size: 0.84rem;
  line-height: 1.45;
}

.import-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  justify-self: start;
  overflow: hidden;
}

.import-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.saved-list {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.saved-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.saved-card strong,
.saved-card span {
  display: block;
}

.saved-card span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.86rem;
}

.saved-actions {
  display: flex;
  gap: 6px;
}

.saved-actions button {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  background: var(--soft);
}

.saved-actions .delete-bill {
  color: var(--danger);
}

.preview-area {
  min-width: 0;
  position: relative;
  z-index: 1;
  overflow-x: auto;
  padding-bottom: 12px;
}

.bill-paper {
  width: 900px;
  max-width: 100%;
  min-height: 1120px;
  margin: 0 auto;
  padding: 0;
  border: 1px solid #d5dbe1;
  background: #fff;
  box-shadow: var(--shadow);
}

.bill-header {
  display: grid;
  grid-template-columns: 38% 62%;
  min-height: 138px;
  background: var(--accent);
}

.logo-box {
  display: grid;
  place-items: center;
  padding: 20px 28px;
  background: #fff;
}

.logo-box img {
  max-width: 100%;
  height: auto;
  display: block;
}

.invoice-title {
  display: grid;
  justify-items: end;
  align-content: center;
  padding: 20px 36px;
  color: #fff;
}

.invoice-title span {
  margin-right: 6px;
  color: #212121;
  font-size: 1.1rem;
  font-weight: 800;
}

.invoice-title strong {
  font-size: 3.9rem;
  line-height: 0.95;
  letter-spacing: 0;
}

.invoice-info {
  display: grid;
  grid-template-columns: 37% 63%;
  background: #fff4e6;
}

.quotation-card {
  min-height: 214px;
  padding: 24px 28px;
  color: #fff;
  background: var(--accent-dark);
}

.quotation-card span,
.bill-meta span,
.signature-box span {
  display: block;
  color: #f58214;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.quotation-card strong {
  display: block;
  margin: 10px 0 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.75);
  font-size: 1.08rem;
}

.quotation-card p {
  margin: 8px 0 0;
  color: #fff;
  font-weight: 800;
  line-height: 1.4;
  white-space: pre-line;
}

.invoice-meta-services {
  padding: 24px 20px 18px;
}

.bill-meta {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  font-size: 1rem;
}

.bill-meta div {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.bill-meta span {
  color: #191919;
  font-size: 1rem;
}

.services-box {
  position: relative;
  padding: 24px 22px 16px;
  border: 1.5px solid #ef9b43;
  border-radius: 10px;
  background: #fff;
  box-shadow: 7px 7px 0 rgba(23, 26, 29, 0.12);
}

.services-box > strong {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  padding: 3px 16px;
  border-radius: 5px;
  color: #fff;
  background: #202020;
  font-size: 1.05rem;
}

.services-box ul {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px 24px;
  margin: 0;
  padding-left: 18px;
  font-size: 0.82rem;
  font-weight: 800;
}

.invoice-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.invoice-table th,
.invoice-table td {
  padding: 13px 12px;
  border: 1.5px solid #20242a;
  text-align: left;
  vertical-align: top;
}

.invoice-table th {
  color: #111418;
  background: var(--accent);
  font-size: 0.98rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.invoice-table tbody tr:nth-child(even) {
  background: #fff;
}

.col-no {
  width: 58px;
}

.invoice-table th:nth-child(2) {
  width: 44%;
}

.invoice-table th:nth-child(3) {
  width: 15%;
}

.invoice-table th:nth-child(4) {
  width: 16%;
}

.invoice-table th:nth-child(5) {
  width: 17%;
}

.numeric {
  text-align: right !important;
}

.bottom-band {
  display: grid;
  grid-template-columns: 37% 1fr 165px;
  border-top: 2px dashed #777;
  background: #fff4e6;
}

.payment-method {
  padding: 14px 26px 18px;
  color: #fff;
  background: var(--accent-dark);
}

.payment-method h3,
.terms-panel h3 {
  margin-bottom: 7px;
  color: #f58214;
}

.payment-method p {
  margin: 0 0 7px;
  font-size: 0.8rem;
  font-weight: 800;
}

.contact-block {
  display: grid;
  justify-items: end;
  gap: 4px;
  margin-top: 14px;
  font-size: 0.82rem;
}

.terms-panel {
  padding: 12px 18px;
}

.word-total-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  border-bottom: 2px solid #7e5d3b;
  font-size: 0.95rem;
}

.word-total-row span {
  font-weight: 800;
}

.terms-panel ul {
  margin: 0;
  padding-left: 18px;
  font-size: 0.64rem;
  line-height: 1.45;
  font-weight: 700;
}

.grand-box {
  display: grid;
  align-content: center;
  justify-items: center;
  color: #fff;
  padding: 12px;
  background: var(--accent);
}

.grand-box span {
  font-size: 1.2rem;
  font-weight: 900;
}

.grand-box strong {
  font-size: 1.8rem;
  text-align: center;
}

.bill-footer {
  display: flex;
  justify-content: flex-end;
  gap: 24px;
  padding: 10px 36px 26px;
  align-items: end;
  background: #fff4e6;
}

.bill-footer p {
  max-width: 440px;
  color: var(--muted);
  line-height: 1.55;
}

.signature-box {
  width: 220px;
  padding-top: 30px;
  text-align: center;
}

.signature-box img {
  display: block;
  max-width: 190px;
  max-height: 72px;
  margin: 0 auto 4px;
  object-fit: contain;
}

.signature-box img[hidden] {
  display: none !important;
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .bill-paper {
    width: 100%;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .panel-heading,
  .bill-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .field-grid,
  .item-row,
  .bill-header,
  .invoice-info,
  .bottom-band {
    grid-template-columns: 1fr;
  }

  .bill-paper {
    min-height: auto;
    padding: 0;
  }

  .services-box ul {
    grid-template-columns: 1fr;
  }
}

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

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

  html,
  body {
    width: 210mm;
    min-height: 297mm;
    background: #fff;
    overflow: visible;
  }

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

  .app-shell {
    max-width: none;
    padding: 0;
    margin: 0;
  }

  .workspace {
    display: block;
  }

  .preview-area {
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  .bill-paper {
    width: 198mm;
    max-width: none;
    min-height: 0;
    height: 285mm;
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    break-inside: avoid;
    page-break-inside: avoid;
    overflow: hidden;
    font-size: 9px;
  }

  .bill-header {
    grid-template-columns: 38% 62% !important;
    min-height: 34mm;
  }

  .logo-box {
    padding: 5mm 8mm;
  }

  .invoice-title {
    padding: 5mm 9mm;
  }

  .invoice-title strong {
    font-size: 34pt;
  }

  .invoice-info {
    grid-template-columns: 37% 63% !important;
  }

  .quotation-card {
    min-height: 43mm;
    padding: 6mm 7mm;
  }

  .quotation-card strong {
    margin: 2mm 0 4mm;
    padding-bottom: 3mm;
    font-size: 10pt;
  }

  .quotation-card p {
    font-size: 9pt;
    line-height: 1.35;
  }

  .invoice-meta-services {
    padding: 6mm 5mm 4mm;
  }

  .bill-meta {
    margin-bottom: 6mm;
    font-size: 9pt;
  }

  .bill-meta span {
    font-size: 9pt;
  }

  .services-box {
    padding: 7mm 5mm 3mm;
    border-radius: 3mm;
    box-shadow: 2mm 2mm 0 rgba(23, 26, 29, 0.12);
  }

  .services-box > strong {
    top: -4mm;
    font-size: 9pt;
  }

  .services-box ul {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 1.8mm 5mm;
    font-size: 7pt;
  }

  .invoice-table th,
  .invoice-table td {
    padding: 2.8mm 3mm;
    border-width: 0.4mm;
  }

  .invoice-table th {
    font-size: 8pt;
  }

  .bottom-band {
    grid-template-columns: 37% 1fr 31mm !important;
  }

  .payment-method {
    padding: 3.2mm 6mm 4mm;
  }

  .payment-method h3,
  .terms-panel h3 {
    margin-bottom: 1.5mm;
    font-size: 9pt;
  }

  .payment-method p,
  .contact-block {
    font-size: 6.8pt;
  }

  .terms-panel {
    padding: 3mm 4mm;
  }

  .word-total-row {
    margin-bottom: 3mm;
    font-size: 7.6pt;
  }

  .terms-panel ul {
    font-size: 5.6pt;
    line-height: 1.35;
  }

  .grand-box span {
    font-size: 10pt;
  }

  .grand-box strong {
    font-size: 15pt;
  }

  .bill-footer {
    flex-direction: row !important;
    justify-content: flex-end;
    align-items: end;
    padding: 6mm 8mm 8mm;
  }

  .signature-box {
    width: 48mm;
    padding-top: 0;
  }

  .signature-box img {
    max-width: 42mm;
    max-height: 18mm;
  }
}
