:root {
  --bg: #eef3f9;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-solid: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #dbe4ee;
  --primary: #1e3a5f;
  --secondary: #2563eb;
  --accent: #059669;
  --danger: #dc2626;
  --shadow-soft: 0 24px 60px rgba(15, 23, 42, 0.08);
  --shadow-card: 0 18px 38px rgba(15, 23, 42, 0.12);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Open Sans", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.12), transparent 24%),
    radial-gradient(circle at 85% 10%, rgba(5, 150, 105, 0.1), transparent 20%),
    linear-gradient(180deg, #f8fbff 0%, #eef3f9 100%);
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 24px;
  min-height: 100vh;
  padding: 24px;
}

.editor-panel,
.preview-shell {
  min-width: 0;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel-header,
.panel-card,
.preview-topbar,
.invoice-stage {
  border: 1px solid rgba(219, 228, 238, 0.85);
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-soft);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  padding: 24px;
  border-radius: var(--radius-xl);
}

.panel-header h1,
.preview-topbar h2 {
  margin: 0;
  font-family: "Poppins", sans-serif;
  font-size: clamp(1.6rem, 2vw, 2rem);
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.status-chip {
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.08);
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-card {
  padding: 20px;
  border-radius: var(--radius-lg);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.section-heading h2 {
  margin: 0;
  font-family: "Poppins", sans-serif;
  font-size: 1rem;
}

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

.field,
.upload-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field span {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

.field input,
.field select,
.field textarea,
.saved-clients-row select {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--ink);
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.field textarea {
  min-height: 110px;
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.saved-clients-row select:focus {
  outline: none;
  border-color: rgba(37, 99, 235, 0.6);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

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

.saved-clients-row,
.action-row {
  display: flex;
  gap: 12px;
}

.saved-clients-row select {
  flex: 1;
}

.ghost-button,
.secondary-button,
.primary-button,
.danger-button {
  min-height: 46px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

.ghost-button {
  background: rgba(30, 58, 95, 0.06);
  color: var(--primary);
}

.secondary-button {
  flex: 1;
  background: #fff;
  border-color: var(--border);
  color: var(--ink);
}

.primary-button {
  flex: 1.2;
  background: var(--primary);
  color: #fff;
  box-shadow: 0 12px 28px rgba(30, 58, 95, 0.24);
}

.danger-button {
  background: rgba(220, 38, 38, 0.08);
  color: var(--danger);
}

.ghost-button:hover,
.secondary-button:hover,
.primary-button:hover,
.danger-button:hover {
  transform: translateY(-1px);
}

.items-editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.item-editor-row {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) 90px 110px 44px;
  gap: 10px;
  align-items: end;
}

.remove-item-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid rgba(220, 38, 38, 0.18);
  background: rgba(220, 38, 38, 0.08);
  color: var(--danger);
  font-weight: 700;
}

.preview-shell {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.preview-topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-end;
  padding: 24px;
  border-radius: var(--radius-xl);
}

.preview-summary {
  text-align: right;
}

.preview-summary span {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
}

.preview-summary strong {
  display: block;
  margin-top: 8px;
  font-family: "Poppins", sans-serif;
  font-size: clamp(1.5rem, 2vw, 2.2rem);
}

.invoice-stage {
  padding: 26px;
  border-radius: calc(var(--radius-xl) + 4px);
}

.invoice-paper {
  width: 100%;
  max-width: 920px;
  margin: 0 auto;
  padding: clamp(24px, 4vw, 42px);
  border-radius: 28px;
  background: var(--panel-solid);
  box-shadow: var(--shadow-card);
}

.invoice-paper.pdf-export {
  max-width: 794px;
  padding: 22px;
  border-radius: 0;
  box-shadow: none;
}

.invoice-paper.pdf-export .invoice-header {
  gap: 16px;
}

.invoice-paper.pdf-export .invoice-client-service,
.invoice-paper.pdf-export .invoice-footer-grid,
.invoice-paper.pdf-export .invoice-table-section {
  margin-top: 16px;
}

.invoice-paper.pdf-export .invoice-card,
.invoice-paper.pdf-export .invoice-meta-card,
.invoice-paper.pdf-export .totals-card {
  padding: 16px;
  border-radius: 18px;
}

.invoice-paper.pdf-export .logo-frame {
  width: 72px;
  height: 72px;
  border-radius: 18px;
}

.invoice-paper.pdf-export .company-name {
  font-size: 1.3rem;
}

.invoice-paper.pdf-export .company-meta,
.invoice-paper.pdf-export .invoice-card p,
.invoice-paper.pdf-export .notes-card p,
.invoice-paper.pdf-export .totals-row span,
.invoice-paper.pdf-export .invoice-meta-grid span {
  font-size: 0.84rem;
}

.invoice-paper.pdf-export .table-head {
  padding: 14px 16px;
}

.invoice-paper.pdf-export .table-row {
  padding: 14px 16px;
}

.invoice-paper.pdf-export .payment-methods {
  margin-top: 12px;
}

.invoice-paper.pdf-export .payment-badge svg,
.invoice-paper.pdf-export .payment-badge img {
  height: 24px;
}

.invoice-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 24px;
  align-items: start;
}

.brand-block {
  display: flex;
  align-items: flex-start;
  gap: 18px;
}

.logo-frame {
  width: 84px;
  height: 84px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #f8fafc 0%, #edf3f9 100%);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}

.logo-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.company-name {
  margin: 0;
  font-family: "Poppins", sans-serif;
  font-size: 1.5rem;
}

.company-meta {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.invoice-meta-card,
.invoice-card,
.totals-card {
  border: 1px solid var(--border);
  border-radius: 22px;
  background: #fbfdff;
}

.invoice-meta-card {
  padding: 20px;
}

.invoice-label,
.section-tag {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.invoice-meta-card h3,
.invoice-card h4 {
  margin: 0;
  font-family: "Poppins", sans-serif;
}

.invoice-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.invoice-meta-grid span,
.totals-row span {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
}

.invoice-meta-grid strong,
.totals-row strong {
  display: block;
  margin-top: 6px;
}

.invoice-client-service,
.invoice-footer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-top: 22px;
}

.invoice-card {
  padding: 18px;
}

.invoice-card p,
.notes-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.service-details {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.service-details span {
  padding: 8px 10px;
  border-radius: 999px;
  background: #eef3f8;
  color: var(--primary);
  font-size: 0.8rem;
  font-weight: 700;
}

.invoice-table-section {
  margin-top: 22px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 24px;
}

.table-head,
.table-row {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) 100px 120px 120px;
  gap: 14px;
  align-items: center;
}

.table-head {
  padding: 16px 18px;
  background: #f3f7fb;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.table-body {
  background: #fff;
}

.table-row {
  padding: 18px;
  border-top: 1px solid #eef2f7;
}

.table-row:first-child {
  border-top: 0;
}

.table-row strong {
  font-family: "Poppins", sans-serif;
}

.totals-card {
  padding: 20px;
}

.totals-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
}

.grand-total {
  margin-top: 6px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.grand-total strong {
  font-family: "Poppins", sans-serif;
  font-size: 1.5rem;
  color: var(--primary);
}

.payment-methods {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.payment-badge {
  display: inline-flex;
  align-items: center;
}

.payment-badge svg,
.payment-badge img {
  display: block;
  height: 28px;
  width: auto;
}

.ath-badge {
  padding: 4px 10px;
  border-radius: 999px;
  background: #f4f7fb;
  border: 1px solid #dbe4ee;
}

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

@media (max-width: 860px) {
  .invoice-header,
  .invoice-client-service,
  .invoice-footer-grid {
    grid-template-columns: 1fr;
  }

  .table-head,
  .table-row {
    grid-template-columns: minmax(0, 1fr) 80px 100px 100px;
  }
}

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

  .panel-header,
  .preview-topbar,
  .invoice-stage,
  .panel-card {
    padding: 18px;
  }

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

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

  .item-editor-row .field:first-child {
    grid-column: 1 / -1;
  }

  .action-row,
  .saved-clients-row,
  .preview-topbar {
    flex-direction: column;
  }

  .preview-summary {
    text-align: left;
  }

  .invoice-paper {
    padding: 18px;
    border-radius: 22px;
  }

  .brand-block {
    flex-direction: column;
  }

  .table-head {
    display: none;
  }

  .table-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .table-row > div {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.92rem;
  }

  .table-row > div::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }
}

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

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

  .app-shell,
  .preview-shell,
  .invoice-stage {
    display: block;
    padding: 0;
    background: #fff;
    border: 0;
    box-shadow: none;
  }

  .invoice-paper {
    max-width: none;
    box-shadow: none;
    border-radius: 0;
  }
}
