/* =============================================
   GLASS INVOICE GENERATOR — FULL STYLESHEET
   ============================================= */

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

body {
  font-family: 'Inter', Arial, sans-serif;
  background: #dde1e7;
  color: #1e293b;
  font-size: 13px;
  line-height: 1.4;
}

/* ===== TOPBAR ===== */
.topbar {
  position: sticky; top: 0; z-index: 300;
  height: 54px;
  background: #1e293b;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  box-shadow: 0 2px 12px rgba(0,0,0,.3);
}
.topbar-brand {
  display: flex; align-items: center; gap: 9px;
  flex-shrink: 0;
}
.brand-name {
  font-size: .92rem; font-weight: 700; color: #f1f5f9;
  white-space: nowrap;
}
.brand-sub { color: #64748b; font-weight: 400; font-size: .72rem; }

.topbar-center {
  flex: 1; display: flex; justify-content: center; padding: 0 16px;
}
.tip-text {
  font-size: .73rem; color: #64748b;
  background: rgba(255,255,255,.05);
  border: 1px solid #334155;
  border-radius: 20px;
  padding: 4px 14px;
  white-space: nowrap;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.topbar-sep { width: 1px; height: 24px; background: #334155; margin: 0 4px; }

.btn-dl {
  display: flex; align-items: center; gap: 5px;
  padding: 7px 16px; border-radius: 7px; border: none;
  font-size: .78rem; font-weight: 600; cursor: pointer; color: #fff;
  transition: all .15s; font-family: 'Inter', sans-serif;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.btn-dl:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,.3); filter: brightness(1.08); }
.btn-dl:active { transform: translateY(0); }
.btn-dl.pdf  { background: #dc2626; }
.btn-dl.jpg  { background: #7c3aed; }
.btn-dl.word { background: #059669; }

.btn-icon {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 7px;
  border: 1px solid #475569; background: transparent; color: #94a3b8;
  cursor: pointer; transition: all .15s;
}
.btn-icon:hover { background: #334155; color: #f1f5f9; border-color: #64748b; }

/* ===== WORKSPACE ===== */
.workspace {
  display: flex;
  height: calc(100vh - 54px);
  overflow: hidden;
}

/* ===== EDITOR PANEL (LIGHT MODE) ===== */
.editor-panel {
  width: 420px; min-width: 420px;
  background: #f8fafc;
  border-right: 1px solid #e2e8f0;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 2px 0 12px rgba(0,0,0,.06);
  transition: width .25s ease, min-width .25s ease;
}
.editor-panel.hidden { width: 0; min-width: 0; overflow: hidden; }

/* TABS */
.editor-tabs {
  display: flex; flex-wrap: wrap; gap: 2px;
  padding: 10px 10px 0;
  background: #f1f5f9;
  border-bottom: 2px solid #e2e8f0;
  flex-shrink: 0;
}
.etab {
  padding: 7px 12px; border-radius: 8px 8px 0 0;
  border: none; background: transparent;
  font-size: .72rem; font-weight: 600; cursor: pointer;
  color: #64748b; font-family: 'Inter', sans-serif;
  transition: all .15s; white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.etab:hover { background: #e2e8f0; color: #1e293b; }
.etab.active { background: #fff; color: #2563eb; border-bottom-color: #fff; border-color: #e2e8f0 #e2e8f0 #fff; border-width: 1px 1px 2px; }

/* TAB CONTENT */
.tab-content {
  display: none; flex: 1; overflow-y: auto;
  padding: 14px 14px 24px;
}
.tab-content.active { display: block; }
.tab-content::-webkit-scrollbar { width: 5px; }
.tab-content::-webkit-scrollbar-track { background: #f1f5f9; }
.tab-content::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* FIELD GROUPS */
.field-group {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.04);
}
.fg-title {
  font-size: .68rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  color: #94a3b8; margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f1f5f9;
}

.field-row { margin-bottom: 9px; }
.field-row:last-child { margin-bottom: 0; }
.field-row label {
  display: block; font-size: .71rem; font-weight: 600;
  color: #475569; margin-bottom: 4px;
}

.field-2col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
  margin-bottom: 9px;
}
.field-2col:last-child { margin-bottom: 0; }
.field-2col .field-row { margin-bottom: 0; }

.field-row input[type=text],
.field-row input[type=email],
.field-row input[type=number],
.field-row input[type=date],
.field-row select,
.field-row textarea,
.field-2col input[type=text],
.field-2col input[type=email],
.field-2col input[type=number],
.field-2col input[type=date],
.field-2col select {
  width: 100%; padding: 8px 10px;
  border: 1.5px solid #e2e8f0; border-radius: 7px;
  background: #f8fafc; color: #1e293b;
  font-size: .8rem; font-family: 'Inter', sans-serif;
  transition: border-color .15s, box-shadow .15s;
}
.field-row input:focus, .field-row select:focus, .field-row textarea:focus,
.field-2col input:focus, .field-2col select:focus {
  outline: none; border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
  background: #fff;
}
.field-row textarea { width: 100%; resize: vertical; min-height: 70px; border: 1.5px solid #e2e8f0; border-radius: 7px; background: #f8fafc; color: #1e293b; font-size: .8rem; font-family: 'Inter', sans-serif; padding: 8px 10px; transition: border-color .15s, box-shadow .15s; }
.field-row textarea:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.12); background: #fff; }
.inp-full { width: 100%; }

.checkbox-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid #f1f5f9;
}
.checkbox-row label { font-size: .76rem; color: #475569; cursor: pointer; }
.checkbox-row input[type=checkbox] { width: 15px; height: 15px; accent-color: #2563eb; cursor: pointer; }

.upload-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 7px;
  border: 1.5px dashed #2563eb; color: #2563eb;
  background: #eff6ff; font-size: .76rem; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.upload-btn:hover { background: #2563eb; color: #fff; }

/* ITEMS EDITOR */
.items-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.btn-add-item {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 7px;
  border: 1.5px solid #2563eb; background: #eff6ff;
  color: #2563eb; font-size: .76rem; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.btn-add-item:hover { background: #2563eb; color: #fff; }
.items-count { font-size: .72rem; color: #94a3b8; font-weight: 500; }

.item-card {
  background: #fff; border: 1.5px solid #e2e8f0;
  border-radius: 10px; margin-bottom: 8px; overflow: hidden;
}
.item-card-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px;
  background: #f8fafc; border-bottom: 1px solid #e2e8f0;
  cursor: pointer;
}
.item-card-hdr .item-num {
  font-size: .75rem; font-weight: 700; color: #2563eb;
  background: #dbeafe; padding: 2px 8px; border-radius: 4px;
}
.item-card-hdr .item-desc-preview {
  flex: 1; margin: 0 8px; font-size: .73rem; color: #64748b;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.btn-del-item {
  border: none; background: #fee2e2; color: #ef4444;
  border-radius: 5px; padding: 3px 8px; cursor: pointer; font-size: .7rem; font-weight: 600;
  transition: all .15s;
}
.btn-del-item:hover { background: #ef4444; color: #fff; }
.btn-collapse-item { background: none; border: none; cursor: pointer; color: #94a3b8; font-size: .9rem; transition: transform .2s; }
.btn-collapse-item.open { transform: rotate(180deg); }

.item-card-body { padding: 10px 12px; }
.item-card-body.hidden { display: none; }
.item-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.item-4col { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.item-field label { font-size: .65rem; font-weight: 600; color: #94a3b8; display: block; margin-bottom: 3px; }
.item-field input {
  width: 100%; padding: 5px 8px; border: 1.5px solid #e2e8f0;
  border-radius: 6px; background: #f8fafc; color: #1e293b;
  font-size: .75rem; font-family: 'Inter', sans-serif;
}
.item-field input:focus { outline: none; border-color: #2563eb; background: #fff; }

/* ===== PREVIEW AREA ===== */
.preview-area {
  flex: 1; overflow: hidden;
  background: #dde1e7;
  display: flex; flex-direction: column;
}

.preview-scroll {
  flex: 1; overflow: auto;
  padding: 28px 20px 40px;
}
.preview-scroll::-webkit-scrollbar { width: 7px; height: 7px; }
.preview-scroll::-webkit-scrollbar-track { background: #d0d4da; border-radius: 4px; }
.preview-scroll::-webkit-scrollbar-thumb { background: #a0aab4; border-radius: 4px; }

.a4-pages-container {
  display: flex; flex-direction: column; align-items: center;
  gap: 0; /* pages touch each other – page-break line separates them */
}

/* ===== A4 PAGE ===== */
.a4-page {
  width: 794px;
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,.18), 0 1px 4px rgba(0,0,0,.1);
  position: relative;
  padding: 22px 26px;
  font-family: Arial, sans-serif;
  font-size: 10.5px;
  color: #000;
  /* NO min-height — grows naturally with content */
}

/* Page break separator between pages */
.page-break-bar {
  width: 794px;
  height: 20px;
  background: linear-gradient(to bottom, #c0c8d4, #dde1e7, #c0c8d4);
  display: flex; align-items: center; justify-content: center;
  font-size: .6rem; color: #94a3b8; letter-spacing: .1em;
  font-family: 'Inter', sans-serif; text-transform: uppercase;
}

/* ===== CONTENTEDITABLE STYLES ===== */
.ce {
  outline: none;
  border-radius: 2px;
  transition: background .15s, box-shadow .15s;
  /* NO display:inline — let divs be block, spans be inline naturally */
}
.ce:hover { background: rgba(37,99,235,.05); }
.ce:focus {
  background: #fff9c4;
  box-shadow: 0 0 0 2px #f59e0b;
  border-radius: 2px;
}
[contenteditable="true"] { cursor: text; }

/* ===== INV SHARED TABLE STYLES ===== */
.inv-table {
  width: 100%; border-collapse: collapse;
}
.inv-table td, .inv-table th {
  border: 1px solid #000;
  padding: 2px 4px;
  vertical-align: middle;
  font-size: 10px;
}

/* ===== HEADER TABLE ===== */
.hdr-table td { border: 1px solid #000; padding: 5px 6px; vertical-align: top; }
.logo-cell { text-align: center; vertical-align: middle; }
.logo-ph { display: flex; justify-content: center; align-items: center; }

.company-info-cell { text-align: center; padding: 6px 12px !important; vertical-align: middle; }
.company-name {
  font-size: 17px; font-weight: 900;
  font-family: Arial Black, Arial, sans-serif;
  margin-bottom: 3px;
}
.company-addr   { font-size: 9.5px; margin-bottom: 2px; }
.company-contact{ font-size: 9.5px; margin-bottom: 3px; }
.company-legal  { font-size: 9.5px; line-height: 1.65; }
.doc-tag-cell { text-align: center; vertical-align: bottom; padding: 5px 4px !important; }
.doc-tag { font-size: 10px; font-weight: 700; }

/* INVOICE TYPE ROW */
.inv-type-cell { text-align: center; padding: 4px !important; border: 1px solid #000; }
.inv-type { font-size: 13px; font-weight: 700; }

/* META TABLES */
.ml { font-weight: 600; font-size: 10px; white-space: nowrap; padding: 2px 5px !important; }
.mv { font-size: 10px; min-width: 60px; padding: 2px 5px !important; }
.bv { font-weight: 700; }

/* CLIENT */
.client-cell { border: 1px solid #000; padding: 5px 7px !important; vertical-align: top; }
.client-hdr { font-weight: 700; font-size: 10.5px; margin-bottom: 3px; }
.client-body { font-size: 9.5px; line-height: 1.6; }

/* ACCOUNT BAR */
.acct-bar td { background: #f5f5f5; }

/* GROUP HEADER */
.grp-hdr-table td { font-weight: 700; font-size: 10px; padding: 2px 5px !important; border: 1px solid #000; }
.grp-sr-cell { width: 22px; text-align: center; }
.grp-part-cell { width: 120px; font-family: 'Courier New', monospace; }

/* ITEMS TABLE */
.items-table th {
  background: #e8e8e8; font-weight: 700; font-size: 9.5px;
  line-height: 1.25; text-align: center;
}
.th-grp { background: #d4d4d4 !important; }
.items-table td { font-size: 10px; text-align: center; }
.tc { text-align: center; }
.tr { text-align: right; }
.subtotal-row td { background: #f0f0f0; font-weight: 700; }

/* CHARGES */
.charges-table td { border: 1px solid #000; padding: 2px 5px !important; font-size: 10px; }
.charges-hsn { font-weight: 600; }
.charges-lbl { font-weight: 600; padding-left: 18px !important; }

/* TOTAL SUMMARY */
.total-summary-table td { border: 1px solid #000; padding: 3px 5px !important; font-size: 10px; }
.ts-lbl { font-weight: 700; text-align: center; background: #e8e8e8; width: 120px; }
.grand-cell { font-weight: 800; font-size: 11.5px; }

/* BOTTOM */
.bottom-table td { border: 1px solid #000; padding: 3px 7px !important; font-size: 9.5px; vertical-align: top; }
.bank-cell { width: 44%; padding: 7px 9px !important; }
.bank-title { font-weight: 800; font-size: 10.5px; margin-bottom: 5px; text-decoration: underline; }
.bank-row { margin-bottom: 2.5px; font-size: 9.5px; }
.fin-lbl { font-weight: 600; font-size: 9.5px; white-space: nowrap; }
.fin-type { width: 25px; text-align: center; }
.fin-pct { width: 60px; text-align: right; font-size: 9.5px; }
.fin-val { width: 85px; text-align: right; font-weight: 600; font-size: 10px; }
.fin-grand-lbl { font-weight: 800; font-size: 10.5px; text-align: center; background: #e8e8e8; }
.fin-grand-val { text-align: right; font-weight: 900; font-size: 12px; }
.fin-words-cell { font-size: 9.5px; line-height: 1.5; }

/* NOTES */
.notes-table td { border: 1px solid #000; padding: 5px 8px !important; font-size: 9.5px; line-height: 1.6; }
.notes-lbl { font-weight: 700; font-size: 10px; margin-bottom: 2px; }

/* REMARK */
.remark-table td { border: 1px solid #000; padding: 3px 7px !important; font-size: 9.5px; }

/* INV FOOTER */
.inv-footer {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 8px;
  border: 1px solid #000; border-top: none;
  font-size: 9px; background: #fafafa;
}

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 20px; right: 20px;
  padding: 11px 20px; border-radius: 8px;
  background: #1e293b; color: #fff; font-size: .8rem; font-weight: 500;
  box-shadow: 0 6px 24px rgba(0,0,0,.3);
  transform: translateY(60px); opacity: 0;
  transition: all .28s cubic-bezier(.4,0,.2,1); z-index: 9999; pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.ok  { background: #059669; }
.toast.err { background: #dc2626; }

/* ===== PRINT ===== */
@media print {
  @page { size: A4 portrait; margin: 10mm; }
  body { background: #fff !important; }
  .topbar, .editor-panel, .toast { display: none !important; }
  .workspace { display: block !important; height: auto !important; }
  .preview-area { display: block !important; overflow: visible !important; }
  .preview-scroll { padding: 0 !important; overflow: visible !important; display: block !important; }
  .a4-pages-container { gap: 0 !important; align-items: flex-start !important; }
  .page-break-bar { display: none !important; }
  .a4-page { width: 100% !important; padding: 0 !important; box-shadow: none !important; page-break-after: always; }
  .ce:hover, .ce:focus { background: transparent !important; box-shadow: none !important; }
}
