* {
  box-sizing: border-box;
}

:root {
  --lime: #c8ff1f;
  --panel: #171717;
  --panel-border: #303030;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Space Grotesk", Arial, sans-serif;
  background: #101010;
}

body {
  padding: 24px;
}

button, input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 24px;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}

.editor-panel {
  background: var(--panel);
  color: #fff;
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 20px;
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 40px);
  overflow: auto;
}

.editor-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--panel-border);
}

.editor-brand h1 {
  margin: 0;
  font-size: 20px;
}

.editor-brand p {
  margin: 4px 0 0;
  color: #9a9a9a;
  font-size: 12px;
}

.editor-section {
  padding: 16px 0;
  border-bottom: 1px solid var(--panel-border);
}

.editor-section h2 {
  font-size: 13px;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin: 0 0 12px;
  color: var(--lime);
}

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

label {
  display: block;
  color: #bebebe;
  font-size: 12px;
  margin: 10px 0;
}

input,
select {
  width: 100%;
  margin-top: 5px;
  border: 1px solid #383838;
  background: #0e0e0e;
  color: #fff;
  padding: 10px 11px;
  border-radius: 9px;
  outline: none;
  font: inherit;
}

input:focus,
select:focus {
  border-color: var(--lime);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.item-editor {
  background: #101010;
  border: 1px solid var(--panel-border);
  padding: 10px;
  border-radius: 12px;
  margin-bottom: 10px;
}

.item-editor-grid {
  display: grid;
  grid-template-columns: 1fr 82px 54px;
  gap: 6px;
  align-items: end;
}

.item-label {
  display: block;
  font-size: 10px;
  color: #929292;
  margin: 0 0 3px;
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}

.item-editor input {
  margin: 0;
  padding: 8px 8px;
  font-size: 12.5px;
}

.item-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid #232323;
}

.item-total-preview {
  font-size: 11px;
  color: #888;
}

.item-total-preview b {
  color: var(--lime);
}

.small-btn,
.secondary-btn,
.primary-btn {
  border: 0;
  cursor: pointer;
  border-radius: 9px;
  font-weight: 700;
}

.small-btn {
  background: var(--lime);
  color: #000;
  padding: 7px 10px;
  font-size: 11px;
}

.remove-item {
  border: 0;
  background: transparent;
  color: #ff8c8c;
  cursor: pointer;
  font-size: 11px;
  padding: 0;
  margin: 0;
}

.remove-item:hover {
  text-decoration: underline;
}

.editor-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}

.editor-actions-secondary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.primary-btn {
  background: var(--lime);
  color: #000;
  padding: 12px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13.5px;
  transition: opacity 0.2s, transform 0.1s;
}

.primary-btn:hover:not(:disabled) {
  opacity: 0.92;
}

.primary-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.primary-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.secondary-btn {
  background: #2b2b2b;
  color: #fff;
  padding: 10px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  transition: background-color 0.2s;
}

.secondary-btn:hover {
  background: #383838;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.spin {
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

.print-tip {
  font-size: 10px;
  line-height: 1.5;
  color: #858585;
  margin: 10px 2px 0;
}

.preview-wrap {
  overflow: auto;
  padding-bottom: 30px;
}

.invoice-page {
  width: 794px;
  height: 1123px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: #000 url("assets/invoice-background.png") center center / cover no-repeat;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
  -webkit-print-color-adjust: exact !important;
  print-color-adjust: exact !important;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

.overlay {
  position: absolute;
  color: #ffffff;
}

.invoice-meta {
  top: 169px;
  right: 71px;
  width: 150px;
  text-align: right;
  font-size: 14px;
  line-height: 1.5;
  font-weight: 600;
}

.invoice-no {
  color: #c8ff1f;
}

.invoice-date-label,
.invoice-date {
  color: #ffffff;
}

.invoice-rows {
  top: 335px;
  left: 122px;
  width: 580px;
  color: #262626;
  font-size: 13px;
  font-weight: 500;
}

.invoice-row {
  display: grid;
  grid-template-columns: 214px 166px 80px 120px;
  align-items: center;
  min-height: 41px;
  border-bottom: 1px solid rgba(120, 120, 120, 0.28);
}

.invoice-row:last-child {
  border-bottom: 1px solid rgba(120, 120, 120, 0.28);
}

.invoice-row .desc {
  padding-right: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-row .price {
  text-align: center;
  white-space: nowrap;
}

.invoice-row .qty {
  text-align: center;
  white-space: nowrap;
}

.invoice-row .total {
  text-align: center;
  white-space: nowrap;
  font-weight: 700;
}

.totals-box {
  right: 130px;
  top: 553px;
  width: 140px;
  color: #303524;
  text-align: right;
}

.totals-box .value {
  height: 35px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-size: 13px;
  font-weight: 700;
}

.totals-box .total {
  height: 35px;
  color: #111;
  font-size: 13.5px;
}

.client-box {
  left: 74px;
  top: 750px;
  width: 160px;
  color: #fff;
  font-size: 12.5px;
  line-height: 1.36;
  font-weight: 500;
  text-transform: uppercase;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: #bebebe;
  font-size: 12px;
  margin: 8px 0;
  user-select: none;
}

.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--lime);
  cursor: pointer;
}

.invoice-page.no-preview-bg {
  background-image: none !important;
  background-color: #121212 !important;
  border: 1px dashed #3a3a3a;
}

@media (max-width: 1160px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .editor-panel {
    position: static;
    max-height: none;
  }
}

@media print {
  @page {
    size: A4 portrait;
    margin: 0;
  }

  html, body {
    width: 210mm;
    height: 297mm;
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .editor-panel {
    display: none !important;
  }

  .app-shell,
  .preview-wrap {
    display: block !important;
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    background: transparent !important;
  }

  .invoice-page {
    width: 210mm !important;
    height: 297mm !important;
    margin: 0 !important;
    box-shadow: none !important;
    break-after: avoid;
    page-break-after: avoid;
    background: none !important;
    background-color: transparent !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* When explicitly enabled by user */
  body.print-with-background {
    background: #000 !important;
  }

  body.print-with-background .app-shell,
  body.print-with-background .preview-wrap {
    background: #000 !important;
  }

  body.print-with-background .invoice-page {
    background: #000 url("assets/invoice-background.png") center center / cover no-repeat !important;
  }
}
