:root {
  --blue: #2f6fd6;
  --blue-deep: #1f4f9c;
  --blue-soft: #e8f0fc;
  --ink: #142033;
  --muted: #5b6b82;
  --line: #d7e0ee;
  --panel: #ffffff;
  --bg: #eef3f9;
  --sidebar: #0f1b2d;
  --sidebar-text: #d7e4f5;
  --accent: #3d8bfd;
  --danger: #d64545;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(15, 27, 45, 0.12);
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Outfit", "DM Sans", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(circle at 0% 0%, #d9e8ff 0%, transparent 40%),
    radial-gradient(circle at 100% 100%, #cfe0f8 0%, transparent 35%),
    linear-gradient(160deg, #f4f7fb 0%, #e7eef8 100%);
}

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

.app {
  display: grid;
  grid-template-columns: minmax(340px, 420px) 1fr;
  min-height: 100vh;
}

.sidebar {
  background:
    linear-gradient(180deg, rgba(61, 139, 253, 0.12), transparent 28%),
    linear-gradient(180deg, #12233a 0%, #0c1626 100%);
  color: var(--sidebar-text);
  padding: 22px 18px 28px;
  overflow-y: auto;
  max-height: 100vh;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  padding: 4px 6px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  background: #fff;
  border-radius: 12px;
  padding: 6px;
}

.brand-name {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02em;
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: #8ea6c7;
}

.form {
  display: grid;
  gap: 14px;
}

.panel {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 14px;
}

.panel h2,
.panel-head h2 {
  margin: 0 0 12px;
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.03em;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin: 0;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 0.78rem;
  color: #9eb2cd;
  letter-spacing: 0.02em;
}

label:last-child {
  margin-bottom: 0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(8, 14, 24, 0.55);
  color: #f3f7ff;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(61, 139, 253, 0.7);
  box-shadow: 0 0 0 3px rgba(61, 139, 253, 0.18);
}

textarea {
  resize: vertical;
  min-height: 64px;
}

.row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

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

.item-card {
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 10px;
}

.item-card .item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.item-card .item-top span {
  font-size: 0.75rem;
  color: #8ea6c7;
}

.item-card .row.three {
  display: grid;
  grid-template-columns: 0.7fr 1fr 1fr;
  gap: 8px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn.primary {
  background: linear-gradient(135deg, #3d8bfd, #245ec4);
  color: #fff;
  box-shadow: 0 10px 24px rgba(36, 94, 196, 0.35);
}

.btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.btn.ghost {
  background: transparent;
  color: #9ec0ef;
  border: 1px dashed rgba(158, 192, 239, 0.45);
  padding: 7px 10px;
  font-size: 0.8rem;
}

.btn.danger {
  background: transparent;
  color: #ff8f8f;
  border: none;
  padding: 4px 8px;
  font-size: 0.75rem;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  position: sticky;
  bottom: 0;
  padding-top: 8px;
  background: linear-gradient(180deg, transparent, #0c1626 18%);
}

.actions .btn.primary {
  grid-column: 1 / -1;
}

.company-panel summary {
  cursor: pointer;
  color: #9ec0ef;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.company-panel[open] summary,
.company-panel details[open] summary {
  margin-bottom: 12px;
}

.preview-wrap {
  padding: 22px 24px 40px;
  overflow: auto;
  max-height: 100vh;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.preview-toolbar p {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  color: var(--ink);
}

.badge {
  background: #12233a;
  color: #fff;
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
}

.sheet-scroll {
  display: flex;
  justify-content: center;
}

/* ===== Document (matches sample PDF) ===== */
.document {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  color: #1a2433;
  padding: 18mm 16mm 14mm;
  box-shadow: var(--shadow);
  position: relative;
  display: flex;
  flex-direction: column;
}

.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.doc-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.doc-logo {
  width: 58px;
  height: 58px;
  object-fit: contain;
}

.doc-brand h1 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.15rem;
  letter-spacing: 0.04em;
  font-weight: 800;
  color: #111827;
}

.tagline {
  margin: 4px 0 0;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: #6b7280;
  font-weight: 500;
}

.doc-title-block {
  text-align: right;
}

.doc-title-block h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.85rem;
  color: var(--blue);
  letter-spacing: 0.06em;
  font-weight: 800;
}

.website {
  margin: 6px 0 0;
  font-size: 0.85rem;
  letter-spacing: 0.18em;
  color: #4b5563;
  font-weight: 600;
}

.accent-line {
  height: 3px;
  margin: 16px 0 22px;
  background: linear-gradient(90deg, var(--blue) 0 28%, #c5d3e6 28% 100%);
  border-radius: 99px;
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.label {
  margin: 0 0 6px;
  color: #6b7280;
  font-size: 0.9rem;
}

.client-name {
  margin: 0 0 4px;
  font-size: 1.05rem;
  font-weight: 700;
}

.muted,
.tax-line {
  margin: 2px 0;
  color: #4b5563;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-line;
}

.invoice-meta {
  text-align: right;
  font-size: 0.92rem;
  color: #374151;
}

.invoice-meta p {
  margin: 0 0 6px;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  margin-bottom: 10px;
}

.items-table th {
  background: var(--blue);
  color: #fff;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  padding: 10px 8px;
  font-weight: 700;
}

.items-table td {
  padding: 11px 8px;
  font-size: 0.9rem;
  border-bottom: 1px solid #e5edf7;
}

.items-table tbody tr:nth-child(even) {
  background: var(--blue-soft);
}

.col-no { width: 10%; text-align: center; }
.col-desc { width: 42%; text-align: left; }
.col-qty { width: 12%; text-align: center; }
.col-price,
.col-total { width: 18%; text-align: right; }

.totals-row {
  display: flex;
  justify-content: flex-end;
  margin: 8px 0 18px;
  font-weight: 700;
  font-size: 0.95rem;
}

.totals-row p {
  margin: 0;
}

.pay-total {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 14px;
  margin-bottom: 28px;
}

.payment-box,
.grand-box {
  border-radius: 4px;
  overflow: hidden;
}

.box-head {
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  padding: 10px 14px;
  font-size: 0.92rem;
  letter-spacing: 0.02em;
}

.box-body {
  border: 1px solid #d7e3f4;
  border-top: none;
  padding: 12px 14px;
  min-height: 68px;
  font-size: 0.88rem;
  color: #374151;
}

.box-body p {
  margin: 0 0 6px;
}

.box-body p:last-child {
  margin: 0;
}

.grand-box .box-head {
  min-height: 68px;
  display: flex;
  align-items: center;
  font-size: 1rem;
}

.footer-block {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-top: auto;
  padding-top: 8px;
}

.thanks {
  margin: 0 0 14px;
  font-weight: 700;
  font-size: 1rem;
}

.terms-label {
  margin: 0 0 6px;
  font-weight: 700;
  font-size: 0.9rem;
}

.terms-text {
  margin: 0;
  max-width: 280px;
  color: #4b5563;
  font-size: 0.82rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.sign-block {
  text-align: right;
  min-width: 180px;
  padding-top: 28px;
}

.sign-name {
  margin: 0 0 18px;
  font-family: "Segoe Script", "Comic Sans MS", cursive;
  font-size: 1.25rem;
  color: #1f2937;
}

.sign-company {
  margin: 0;
  font-weight: 700;
  font-size: 0.92rem;
}

.sign-title {
  margin: 4px 0 0;
  color: #4b5563;
  font-size: 0.85rem;
}

.footer-line {
  margin: 22px 0 14px;
}

.doc-contact {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1.3fr;
  gap: 12px;
  align-items: start;
}

.contact-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 0.78rem;
  color: #374151;
  line-height: 1.35;
}

.contact-item p {
  margin: 0;
}

.icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  margin-top: 1px;
  background: var(--blue);
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
}

.icon.phone {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M22 16.92v3a2 2 0 0 1-2.18 2 19.8 19.8 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.12 4.18 2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.96.36 1.9.7 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.34 1.85.57 2.81.7A2 2 0 0 1 22 16.92z'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M22 16.92v3a2 2 0 0 1-2.18 2 19.8 19.8 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6A19.8 19.8 0 0 1 2.12 4.18 2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.13.96.36 1.9.7 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.91.34 1.85.57 2.81.7A2 2 0 0 1 22 16.92z'/%3E%3C/svg%3E");
}

.icon.mail {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M4 4h16v16H4z'/%3E%3Cpath d='m22 6-10 7L2 6'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M4 4h16v16H4z'/%3E%3Cpath d='m22 6-10 7L2 6'/%3E%3C/svg%3E");
}

.icon.pin {
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M12 21s7-4.5 7-11a7 7 0 1 0-14 0c0 6.5 7 11 7 11z'/%3E%3Ccircle cx='12' cy='10' r='2.5'/%3E%3C/svg%3E");
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2'%3E%3Cpath d='M12 21s7-4.5 7-11a7 7 0 1 0-14 0c0 6.5 7 11 7 11z'/%3E%3Ccircle cx='12' cy='10' r='2.5'/%3E%3C/svg%3E");
}

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

  .sidebar {
    max-height: none;
  }

  .preview-wrap {
    max-height: none;
    padding-top: 8px;
  }

  .document {
    width: min(100%, 210mm);
    transform-origin: top center;
  }
}

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

  .sidebar,
  .preview-toolbar {
    display: none !important;
  }

  .app,
  .preview-wrap,
  .sheet-scroll {
    display: block;
    padding: 0;
    margin: 0;
    max-height: none;
    overflow: visible;
  }

  .document {
    box-shadow: none;
    width: 210mm;
    min-height: 297mm;
    margin: 0 auto;
  }
}
