:root {
  --navy: #0e3d6b;
  --blue: #1b6ca8;
  --sky: #3070ae;
  --cyan: #1a95be;
  --orange: #f58220;
  --ink: #111;
  --muted: #5b6570;
  --line: #d8dee6;
  --panel: #f4f7fb;
  --paper: #fff;
  --stamp: #4a4e9a;
  --table-head: #2f75b5;
  --danger: #b42318;
  --ok: #067647;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", Calibri, Arial, sans-serif;
  color: var(--ink);
  background: #e8eef5;
}

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

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 18px;
  background: linear-gradient(90deg, #0c355e 0%, #1a5f96 60%, #1a95be 100%);
  color: #fff;
  box-shadow: 0 2px 10px rgba(12, 53, 94, 0.25);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.brand img { width: 42px; height: 42px; object-fit: contain; background: #fff; border-radius: 50%; }
.brand h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand p { margin: 2px 0 0; font-size: 12px; opacity: 0.85; }
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  border: 0;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  color: #fff;
  background: var(--orange);
}
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: #fff; color: var(--navy); }
.btn.ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.45); }
.btn.danger { background: #9b1c1c; }
.btn.small { padding: 4px 9px; font-size: 12px; }

.layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  min-height: calc(100vh - 64px);
}

.form-pane {
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
  padding: 14px 14px 40px;
}
.preview-pane {
  overflow: auto;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 12px;
}
.card h2 {
  margin: 0 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--navy);
}
.row { display: grid; gap: 8px; margin-bottom: 8px; }
.row.cols-2 { grid-template-columns: 1fr 1fr; }
.row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
label { display: block; font-size: 11px; color: var(--muted); font-weight: 650; margin-bottom: 3px; }
input, select, textarea {
  width: 100%;
  border: 1px solid #cfd7e3;
  border-radius: 7px;
  padding: 7px 8px;
  font-size: 13px;
  background: #fff;
}
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid #b9d6f2;
  border-color: var(--blue);
}
.hint { font-size: 11px; color: var(--muted); margin: 0 0 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; margin: 6px 0; }
.check input { width: auto; }

.items-head, .item-row {
  display: grid;
  grid-template-columns: 1fr 110px 28px;
  gap: 6px;
  align-items: center;
}
.items-head { font-size: 11px; color: var(--muted); font-weight: 650; margin-bottom: 4px; }
.totals-box {
  background: #eef5fb;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}
.totals-box div { display: flex; justify-content: space-between; margin: 3px 0; }
.totals-box .grand { font-weight: 800; color: var(--navy); border-top: 1px solid #c5d6e8; padding-top: 6px; margin-top: 6px; }

details.card { padding: 8px 12px 12px; }
details.card > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 750;
  color: var(--navy);
  list-style: none;
  padding: 4px 0;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: " ▾"; color: var(--blue); }

.preview-wrap {
  transform-origin: top center;
}
.sheet-shadow {
  box-shadow: 0 12px 40px rgba(16, 42, 67, 0.18);
}

/* ========== INVOICE PAGE ========== */
.invoice {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  color: #111;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: Calibri, "Segoe UI", Arial, sans-serif;
  font-size: 11.5px;
  line-height: 1.35;
}
.inv-header {
  position: relative;
  min-height: 28mm;
  padding: 7mm 12mm 3mm;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.inv-header .swoosh {
  position: absolute;
  top: 0;
  right: 0;
  width: 118mm;
  height: 28mm;
  pointer-events: none;
}
.inv-logo { width: 22mm; height: 22mm; object-fit: contain; position: relative; z-index: 1; }
.inv-brand { position: relative; z-index: 1; padding-top: 2mm; }
.inv-brand .co-name {
  font-family: "Libre Baskerville", Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.4px;
  line-height: 1.1;
  white-space: nowrap;
}
.inv-brand .co-name .shree { color: var(--orange); }
.inv-brand .co-name .rest { color: #1b6ca8; }
.inv-brand .rules {
  margin-top: 3px;
  width: 100%;
  border: 0;
  border-top: 1.6px solid var(--orange);
  border-bottom: 1.6px solid #1b6ca8;
  height: 4px;
}
.inv-gstin-top {
  position: absolute;
  right: 14mm;
  top: 18mm;
  font-size: 11px;
  z-index: 2;
}

.inv-body { flex: 1; padding: 1mm 12mm 4mm; position: relative; z-index: 1; }

.inv-footer {
  position: relative;
  margin-top: auto;
  padding: 3mm 12mm 0;
  min-height: 28mm;
}
.inv-contacts {
  display: grid;
  grid-template-columns: 1.1fr 1.2fr 1fr;
  gap: 8px;
  align-items: center;
  padding-bottom: 4mm;
  font-size: 11px;
}
.contact {
  display: flex;
  align-items: center;
  gap: 8px;
}
.icon-circle {
  width: 22px;
  height: 22px;
  min-width: 22px;
  border-radius: 50%;
  background: #1a95be;
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 11px;
  border: 2px solid #0e4f78;
}
.inv-footer .wave {
  display: block;
  width: calc(100% + 24mm);
  margin-left: -12mm;
  height: 16mm;
}
.addr-bar {
  position: absolute;
  left: 12mm;
  right: 10mm;
  bottom: 4.2mm;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
  font-size: 10.5px;
  z-index: 2;
}
.addr-bar .icon-circle { background: #4db7d4; border-color: #0e4f78; }

.stamp {
  width: 28mm;
  height: 28mm;
  opacity: 0.92;
}
.sign-block { text-align: center; width: 48mm; margin-left: auto; position: relative; }
.sign-block .stamp {
  position: absolute;
  left: 50%;
  top: 4mm;
  transform: translateX(-50%);
  pointer-events: none;
}

/* SRT template */
.tax-title {
  text-align: center;
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 0.8px;
  margin: 1mm 0 3mm;
}
.meta-right { text-align: right; font-size: 12px; }
.meta-right b { font-size: 12.5px; }
.fromto {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10mm;
  margin: 3mm 0 2mm;
}
.fromto .who { font-weight: 800; font-size: 12.5px; margin: 1px 0 2px; }
.ids {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10mm;
  margin: 2mm 0 3mm;
  font-size: 11.5px;
}
.subject { font-weight: 800; margin: 2mm 0 1mm; font-size: 12px; }
.enclosed { font-weight: 700; margin: 0 0 3mm; }

table.inv-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
table.inv-table th, table.inv-table td {
  border: 1px solid #111;
  padding: 4px 6px;
  vertical-align: top;
}
table.inv-table th {
  background: var(--table-head);
  color: #fff;
  font-weight: 700;
  text-align: center;
}
.num { text-align: right; white-space: nowrap; }
.ctr { text-align: center; }
.sum-label { text-align: right; font-weight: 650; }
.grand-row { font-weight: 800; }
.grand-row td { background: #e9eef3; }

.words { margin: 3mm 0 1mm; font-weight: 700; }
.note { margin: 1mm 0; }
.bank h3 {
  margin: 4mm 0 2mm;
  font-size: 13px;
  text-decoration: underline;
}
.bank div { margin: 1px 0; }
.srt-sign {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 6mm;
}
.srt-sign .left { font-weight: 800; }
.srt-sign .stamp-wrap { position: relative; width: 38mm; height: 32mm; }
.srt-sign .stamp { position: absolute; right: 0; top: 0; }

/* GST boxed template */
.box {
  border: 1.4px solid #111;
}
.box .title-row {
  text-align: center;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.6px;
  padding: 3px;
  border-bottom: 1px solid #111;
}
.split { display: grid; grid-template-columns: 1.35fr 0.85fr; }
.split > div { padding: 5px 7px; }
.split > div + div { border-left: 1px solid #111; }
.hr { border-top: 1px solid #111; }
.co { font-weight: 800; font-size: 12.5px; }
.kv { margin: 1px 0; }
.kv b { font-weight: 800; }
.gst-table th { background: #fff; color: #111; }
.decl { padding: 5px 7px; font-size: 11px; }
.decl u { font-weight: 700; }
.gst-bottom {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-top: 5mm;
  padding: 0 1mm;
}
.acct h3 { margin: 0 0 3px; font-size: 13px; }
.acct div { margin: 1px 0; }

.original { font-style: italic; text-align: center; margin: -1mm 0 2mm; }
.motto { text-align: center; font-style: italic; margin: 2mm 0; font-weight: 650; }
.grey-note {
  background: #e6e6e6;
  border: 1px solid #bbb;
  padding: 4px 6px;
  font-size: 10px;
  margin-top: 3mm;
}

@media print {
  @page { size: A4; margin: 0; }
  html, body { background: #fff; height: auto; }
  .app-header, .form-pane { display: none !important; }
  .layout { display: block; min-height: auto; }
  .preview-pane { padding: 0; overflow: visible; display: block; }
  .preview-wrap {
    transform: none !important;
    width: 210mm !important;
    margin: 0 !important;
  }
  .sheet-shadow { box-shadow: none; }
  .invoice {
    width: 210mm;
    min-height: 297mm;
    box-shadow: none;
  }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .form-pane { border-right: 0; border-bottom: 1px solid var(--line); max-height: none; }
}
