/* ============================================================
   InvoiceKite — style.css
   invoicekite.com | Clean wide 2-column layout
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── CSS Variables ── */
:root {
  --bg-page:       #f1f5f9;
  --bg-card:       #ffffff;
  --bg-card-hd:    #f8fafc;
  --border:        #e2e8f0;
  --focus:         #6366f1;
  --text:          #0f172a;
  --muted:         #64748b;
  --subtle:        #94a3b8;
  --brand:         #4f46e5;
  --brand-dark:    #4338ca;
  --radius-card:   12px;
  --radius-input:  7px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.06);
}
.dark {
  --bg-page:    #0f172a;
  --bg-card:    #1e293b;
  --bg-card-hd: #0f172a;
  --border:     #334155;
  --text:       #f1f5f9;
  --muted:      #94a3b8;
  --subtle:     #475569;
}
body {
  background: radial-gradient(circle at 10% 0%, #e0e7ff 0, transparent 27rem),
              radial-gradient(circle at 90% 15%, #dbeafe 0, transparent 24rem), var(--bg-page);
  color: var(--text);
}
body.modal-open { overflow: hidden; }

/* ============================================================
   NAVBAR
   ============================================================ */
#main-nav {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.nav-inner {
  max-width: 1600px; margin: 0 auto;
  padding: 0 20px; height: 54px;
  display: flex; align-items: center; gap: 12px;
}
.nav-brand {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none; flex-shrink: 0;
}
.brand-kite  { font-size: 22px; line-height: 1; }
.brand-title { display: block; font-size: 16px; font-weight: 800; color: var(--text); line-height: 1.1; }
.brand-domain{ display: block; font-size: 10px; color: var(--subtle); line-height: 1; }

.mode-tabs {
  display: flex; gap: 2px;
  background: #f1f5f9; border-radius: 10px; padding: 3px;
  flex-shrink: 0;
}
.dark .mode-tabs { background: #334155; }
.mode-tab {
  padding: 4px 12px; font-size: 12px; font-weight: 600;
  color: var(--muted); background: transparent;
  border: none; border-radius: 7px; cursor: pointer;
  transition: all .15s; white-space: nowrap;
}
.mode-tab.active-mode {
  background: #fff; color: var(--brand);
  box-shadow: 0 1px 4px rgba(0,0,0,.1);
}
.dark .mode-tab.active-mode { background: #1e293b; color: #818cf8; }

.nav-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }
.nav-select {
  height: 32px; padding: 0 10px; font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg-card); color: var(--muted);
  cursor: pointer; outline: none;
}
.nav-icon-btn {
  width: 32px; height: 32px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg-card); color: var(--muted);
  cursor: pointer; transition: all .12s; position: relative;
}
.nav-icon-btn:hover { background: #f1f5f9; color: var(--text); }
.dark .nav-icon-btn:hover { background: #334155; }
.nav-icon-btn.active-toggle { background: #eef2ff; color: var(--brand); border-color: #c7d2fe; }
.dark .nav-icon-btn.active-toggle { background: rgba(79,70,229,.2); color: #a5b4fc; border-color: rgba(79,70,229,.4); }
.nav-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 0 12px; height: 34px;
  font-size: 12px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 7px;
  cursor: pointer; transition: all .12s; white-space: nowrap;
  position: relative;
}
.btn-ghost    { background: var(--bg-card); color: var(--muted); }
.btn-ghost:hover { background: #f1f5f9; color: var(--text); }
.dark .btn-ghost:hover { background: #334155; }
.btn-whatsapp { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.btn-whatsapp:hover { background: #bbf7d0; }
.btn-primary  { background: linear-gradient(135deg, #4f46e5, #3730a3); color: #fff; border-color: #4f46e5; box-shadow: 0 4px 12px rgba(79,70,229,.22); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.nav-count-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px;
  font-size: 9.5px; font-weight: 800; line-height: 1;
  background: var(--brand); color: #fff; border-radius: 100px;
}

/* ── Dropdown menu (Tools) ── */
.dropdown-wrap { position: relative; }
.dropdown-menu {
  position: absolute; top: 40px; right: 0;
  min-width: 210px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15,23,42,.16);
  padding: 5px; z-index: 200;
}
.dropdown-item {
  display: flex; align-items: center; gap: 7px; width: 100%;
  text-align: left; padding: 8px 10px; font-size: 12.5px; font-weight: 600;
  color: var(--text); background: none; border: none; border-radius: 7px;
  cursor: pointer; transition: background .1s; white-space: nowrap;
}
.dropdown-item:hover { background: #f1f5f9; }
.dark .dropdown-item:hover { background: #334155; }
.dropdown-item-danger { color: #dc2626; }
.dark .dropdown-item-danger { color: #f87171; }
.dropdown-divider { height: 1px; background: var(--border); margin: 5px 3px; }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed; bottom: 20px; left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: #1e293b; color: #fff;
  padding: 10px 22px; border-radius: 100px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  z-index: 9999; pointer-events: none;
  transition: transform .3s cubic-bezier(.34,1.56,.64,1);
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.ok   { background: #166534; }
.toast.err  { background: #991b1b; }
.toast.info { background: #1e40af; }

/* ============================================================
   MODAL — Invoice History
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(15,23,42,.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; backdrop-filter: blur(2px);
}
.modal-box {
  width: 100%; max-width: 640px; max-height: 82vh;
  background: var(--bg-card); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.modal-title { font-size: 15px; font-weight: 800; color: var(--text); }
.modal-close {
  width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border-radius: 7px; background: none; border: none; color: var(--muted); cursor: pointer;
}
.modal-close:hover { background: #f1f5f9; color: var(--text); }
.dark .modal-close:hover { background: #334155; }

.history-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  padding: 14px 18px 4px; flex-shrink: 0;
}
.hstat {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 10px; background: #f8fafc; border: 1px solid var(--border); border-radius: 9px;
}
.dark .hstat { background: #0f172a; }
.hstat-v { font-size: 13px; font-weight: 800; color: var(--text); }
.hstat-k { font-size: 10px; font-weight: 600; color: var(--subtle); }
.hstat-paid .hstat-v { color: #16a34a; }
.hstat-due  .hstat-v { color: #ea580c; }

.history-search {
  position: relative; padding: 10px 18px; flex-shrink: 0;
}
.history-search-icon { position: absolute; left: 30px; top: 20px; color: var(--subtle); }
.history-search input {
  width: 100%; padding: 8px 12px 8px 32px; font-size: 13px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-card); color: var(--text); outline: none;
}
.history-search input:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.dark .history-search input { background: #0f172a; border-color: #334155; color: #f1f5f9; }

.history-list { overflow-y: auto; padding: 4px 12px 14px; flex: 1; }
.history-empty {
  padding: 40px 20px; text-align: center; color: var(--subtle);
}
.history-empty p { font-size: 13.5px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.history-empty span { font-size: 12px; }

.history-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 8px; border-bottom: 1px solid var(--border);
}
.history-row:last-child { border-bottom: none; }
.hr-main { flex: 1; min-width: 0; }
.hr-top  { display: flex; align-items: center; gap: 8px; }
.hr-inv  { font-size: 13px; font-weight: 700; color: var(--text); }
.hr-sub  { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.hr-amt  { font-size: 13.5px; font-weight: 800; color: var(--text); white-space: nowrap; }
.hr-actions { display: flex; gap: 4px; flex-shrink: 0; }
.hr-act-btn {
  padding: 4px 8px; font-size: 10.5px; font-weight: 700;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-card); color: var(--muted); cursor: pointer;
}
.hr-act-btn:hover { background: #f1f5f9; color: var(--text); }
.dark .hr-act-btn:hover { background: #334155; }
.hr-act-danger { color: #dc2626; border-color: #fecaca; }
.hr-act-danger:hover { background: #fef2f2; }
.dark .hr-act-danger { color: #f87171; border-color: rgba(248,113,113,.3); }

.status-pill {
  font-size: 9.5px; font-weight: 800; padding: 2px 8px; border-radius: 100px;
  border: none; cursor: pointer; white-space: nowrap;
}
.status-pill.paid   { background: #dcfce7; color: #166534; }
.status-pill.unpaid { background: #fef3c7; color: #b45309; }
.dark .status-pill.paid   { background: rgba(22,101,52,.25);  color: #86efac; }
.dark .status-pill.unpaid { background: rgba(180,83,9,.25);   color: #fde68a; }

/* ============================================================
   MAIN LAYOUT — 55/45 split, preview toggleable
   ============================================================ */
.app-main {
  max-width: 1600px; margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 560px;
  gap: 20px;
  min-height: calc(100vh - 54px);
  align-items: start;
}
.app-main.preview-hidden {
  grid-template-columns: 1fr;
}
.app-main.preview-hidden .preview-col {
  display: none;
}
.app-main.preview-hidden .editor-col {
  max-width: 1280px; margin: 0 auto; width: 100%;
}
@media (min-width: 1201px) {
  /* Vyapar-style desktop workspace: dense enough to complete details without endless scrolling. */
  .app-main.preview-hidden { padding-top: 14px; }
  .app-main.preview-hidden .editor-col { gap: 10px; }
  .app-main.preview-hidden .card-head { padding: 10px 14px; }
  .app-main.preview-hidden .card-body { padding: 10px 14px; }
  .app-main.preview-hidden .upload-grid { gap: 10px; margin-bottom: 10px; }
  .app-main.preview-hidden .upload-box { height: 54px; }
  .app-main.preview-hidden .upload-empty { flex-direction: row; gap: 6px; }
  .app-main.preview-hidden .upload-empty svg { width: 17px; height: 17px; }
  .app-main.preview-hidden .upload-row-btns { display: none; }
  .app-main.preview-hidden .field-grid { gap: 8px 10px; }
  .app-main.preview-hidden #india-biz-fields { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .app-main.preview-hidden .finput { padding: 5px 9px; font-size: 12.5px; }
  .app-main.preview-hidden textarea.finput { min-height: 44px; }
  .app-main.preview-hidden .flabel { font-size: 10.5px; margin-bottom: 2px; }
}
@media (max-width: 1200px) {
  .app-main { grid-template-columns: 1fr; }
  .app-main.preview-hidden { grid-template-columns: 1fr; }
  .app-main.preview-hidden .editor-col { max-width: none; }
}

/* ── Editor column ── */
.editor-col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.workspace-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 18px 20px; color: #ffffff; overflow: hidden; position: relative;
  border-radius: 16px; background: linear-gradient(120deg, #172554, #3730a3 58%, #6366f1);
  box-shadow: 0 14px 32px rgba(49, 46, 129, .20);
}
.workspace-banner::after { content: ''; position: absolute; width: 170px; height: 170px; border-radius: 50%; right: -58px; top: -88px; border: 28px solid rgba(255,255,255,.09); }
.workspace-eyebrow { font-size: 10px; font-weight: 800; letter-spacing: .12em; color: #c7d2fe; }
.workspace-banner h1 { font-size: 19px; font-weight: 800; letter-spacing: -.03em; margin: 3px 0; }
.workspace-banner p:last-child { font-size: 12px; color: #e0e7ff; }
.workspace-status { position: relative; z-index: 1; flex-shrink: 0; display: flex; gap: 7px; align-items: center; padding: 7px 10px; background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.2); border-radius: 999px; font-size: 11px; font-weight: 700; }
.workspace-status span { width: 7px; height: 7px; border-radius: 50%; background: #86efac; box-shadow: 0 0 0 3px rgba(134,239,172,.15); }

/* ── Form Cards ── */
.form-card {
  background: var(--bg-card);
  border: 1px solid rgba(203,213,225,.9);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 7px 20px rgba(15,23,42,.055);
  transition: box-shadow .18s ease;
}
.form-card:hover { box-shadow: 0 12px 28px rgba(15,23,42,.08); }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: linear-gradient(90deg, #ffffff, #f8faff);
  border-bottom: 1px solid var(--border);
  cursor: pointer; user-select: none;
  transition: background .12s;
}
.card-head:hover { background: #f1f5f9; }
.dark .card-head:hover { background: #0b1120; }
.card-head.no-toggle { cursor: default; }
.card-head-left  { display: flex; align-items: center; gap: 8px; }
.card-head-right { display: flex; align-items: center; gap: 8px; }
.card-title      { display: flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 800; color: var(--text); }
.section-number  { color: #6366f1; font-size: 10px; letter-spacing: .06em; }
.card-dot        { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 0 0 4px rgba(99,102,241,.10); }
.card-chevron    { font-size: 14px; color: var(--subtle); transition: transform .2s; line-height: 1; }
.card-head.collapsed .card-chevron { transform: rotate(-90deg); }

.saved-badge {
  font-size: 10px; font-weight: 700;
  background: #dcfce7; color: #166534;
  padding: 1px 7px; border-radius: 100px;
}

/* Collapsible body */
.card-body { display: none; padding: 16px; background: linear-gradient(180deg, #ffffff, #fcfdff); }
.card-body.open { display: block; }

/* ── Upload zones ── */
.upload-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px; margin-bottom: 14px;
}
.upload-box-wrap { display: flex; flex-direction: column; gap: 5px; }
.upload-box-label { font-size: 11px; font-weight: 600; color: var(--muted); }
.upload-box {
  height: 86px;
  border: 2px dashed var(--border); border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: #fafbfc; cursor: pointer; overflow: hidden;
  transition: border-color .15s, background .15s;
}
.upload-box:hover { border-color: var(--brand); background: #f5f3ff; }
.dark .upload-box { background: #0f172a; }
.dark .upload-box:hover { background: rgba(99,102,241,.08); }
.upload-empty {
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; pointer-events: none;
}
.upload-empty span { font-size: 11px; color: var(--subtle); }
.upload-preview { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.upload-row-btns { display: flex; gap: 4px; }
.upload-action-btn {
  flex: 1; padding: 4px 0; font-size: 11px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-card); color: var(--muted);
  cursor: pointer; transition: background .12s; text-align: center;
}
.upload-action-btn:hover { background: #f1f5f9; }
.upload-action-btn.remove { color: #ef4444; border-color: #fecaca; }
.upload-action-btn.remove:hover { background: #fef2f2; }
.dark .upload-action-btn { background: #1e293b; }

/* ── Form fields ── */
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-span-2 { grid-column: span 2; }
.field-grid > div:not(.field-grid) {
  padding: 6px 7px 7px; border: 1px solid #edf1f7; border-radius: 10px; background: #fbfcff;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.field-grid > div:not(.field-grid):focus-within { border-color: #a5b4fc; background: #ffffff; box-shadow: 0 4px 12px rgba(79,70,229,.09); }
.dark .card-head { background: linear-gradient(90deg, #1e293b, #172033); }
.dark .card-body { background: linear-gradient(180deg, #1e293b, #172033); }
.dark .field-grid > div:not(.field-grid) { background: #172033; border-color: #334155; }
.dark .field-grid > div:not(.field-grid):focus-within { background: #1e293b; border-color: #6366f1; }
.flabel {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--muted); margin-bottom: 3px; letter-spacing: .01em;
}
.finput {
  display: block; width: 100%;
  padding: 7px 10px; font-size: 13px;
  color: var(--text); background: var(--bg-card);
  border: 1px solid #dbe3ef; border-radius: 7px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
  line-height: 1.4; font-family: inherit;
}
.finput:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
.finput.valid { border-color: #22c55e; }
.finput.error { border-color: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,.1); }
.dark .finput { background: #0f172a; border-color: #334155; color: #f1f5f9; }
.dark .finput:focus { border-color: #818cf8; }
select.finput, textarea.finput { cursor: default; }
.uppercase { text-transform: uppercase; letter-spacing: .04em; }

.section-divider {
  font-size: 11px; font-weight: 700; color: var(--subtle);
  text-transform: uppercase; letter-spacing: .06em;
  padding: 12px 0 6px; border-top: 1px solid var(--border); margin-top: 12px;
}
.input-btn-row { display: flex; gap: 5px; }
.mini-inline-btn {
  flex-shrink: 0; padding: 7px 12px; font-size: 12px; font-weight: 700;
  background: #f1f5f9; border: 1px solid var(--border);
  border-radius: var(--radius-input); color: var(--muted);
  cursor: pointer; transition: background .12s;
}
.mini-inline-btn:hover { background: #e2e8f0; }
.dark .mini-inline-btn { background: #334155; border-color: #475569; color: #cbd5e1; }

/* ── Items Table ── */
.table-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
.items-tbl    { width: 100%; border-collapse: collapse; min-width: 560px; }
.items-thead tr { border-bottom: 2px solid var(--border); }
.items-tbl th {
  padding: 6px 4px; font-size: 10.5px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
}
.th-sm   { width: 62px; text-align: center; }
.th-md   { width: 84px; text-align: right; }
.th-xs   { width: 28px; }
.th-desc { text-align: left; }
.items-tbl tbody tr { border-bottom: 1px solid #f1f5f9; transition: background .1s; }
.items-tbl tbody tr:hover { background: #fafbff; }
.dark .items-tbl tbody tr { border-color: #334155; }
.dark .items-tbl tbody tr:hover { background: rgba(99,102,241,.04); }
.items-tbl td { padding: 4px 3px; vertical-align: middle; }
.row-sr { text-align: center; font-size: 11px; color: var(--subtle); }

.li {
  width: 100%; padding: 5px 6px; font-size: 12px;
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-radius: 5px;
  outline: none; transition: border-color .12s; font-family: inherit;
}
.li:focus { border-color: var(--focus); }
.li.num   { text-align: right; }
.li-sel {
  width: 100%; padding: 5px 3px; font-size: 11.5px;
  background: var(--bg-card); color: var(--text);
  border: 1px solid var(--border); border-radius: 5px;
  outline: none; cursor: pointer; font-family: inherit;
}
.dark .li, .dark .li-sel { background: #0f172a; border-color: #334155; color: #f1f5f9; }
.li-total {
  text-align: right; font-size: 12px; font-weight: 700;
  color: var(--text); padding: 0 4px;
}
.del-btn {
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  border-radius: 5px; background: transparent; border: none;
  color: #cbd5e1; cursor: pointer; transition: all .12s;
}
.del-btn:hover { background: #fee2e2; color: #ef4444; }
.dark .del-btn:hover { background: rgba(239,68,68,.15); }

.add-item-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px; margin: 10px 0 4px;
  font-size: 13px; font-weight: 600;
  color: var(--brand); background: transparent;
  border: 1.5px solid #c7d2fe; border-radius: 8px;
  cursor: pointer; transition: all .15s;
}
.add-item-btn:hover { background: var(--brand); color: #fff; border-color: var(--brand); }
.dark .add-item-btn { border-color: #3730a3; color: #818cf8; }

/* ── Charges ── */
.charges-row {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 10px; padding: 12px 0 4px;
  border-top: 1px solid var(--border); margin-top: 10px;
}
.charge-field .flabel { display: block; margin-bottom: 3px; }
.disc-combo           { display: flex; gap: 3px; }
.disc-type-sel        { width: 42px !important; padding: 7px 3px; }

.round-toggle {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--muted); cursor: pointer; padding: 5px 0;
}
.round-toggle input { width: 14px; height: 14px; accent-color: var(--brand); cursor: pointer; }

/* ── Totals Summary ── */
.totals-summary {
  margin-top: 12px; padding: 12px 14px;
  background: #f8fafc; border: 1px solid var(--border);
  border-radius: 10px;
}
.dark .totals-summary { background: #0f172a; }
.total-row {
  display: flex; justify-content: space-between;
  font-size: 13px; color: var(--muted); padding: 3px 0;
}
.total-row.grand {
  font-size: 15px; font-weight: 800; color: var(--text);
  border-top: 2px solid var(--border); padding-top: 7px; margin-top: 5px;
}
.total-row.grand span:last-child { color: var(--brand); }
.tax-line-row {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--muted); padding: 2px 0;
}
.words-line { font-size: 12px; font-style: italic; color: var(--subtle); margin-top: 7px; }

/* ── Chip buttons ── */
.chip-btn {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 4px 10px; border-radius: 100px; font-size: 11px; font-weight: 700;
  border: 1px solid transparent; cursor: pointer;
  transition: opacity .12s; white-space: nowrap;
}
.chip-btn:hover   { opacity: .82; }
.chip-indigo { background: #eef2ff; color: #4f46e5; border-color: #c7d2fe; }
.chip-green  { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.chip-slate  { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.chip-wa     { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.chip-red    { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.dark .chip-indigo { background: rgba(79,70,229,.2); color: #a5b4fc; border-color: rgba(79,70,229,.4); }
.dark .chip-green  { background: rgba(22,101,52,.2);  color: #86efac; border-color: rgba(22,101,52,.4); }
.dark .chip-slate  { background: #1e293b; color: #94a3b8; border-color: #334155; }
.dark .chip-red    { background: rgba(153,27,27,.2);  color: #fca5a5; border-color: rgba(153,27,27,.4); }

.tax-badge  { font-size: 10.5px; font-weight: 700; padding: 2px 8px; border-radius: 100px; }
.badge-intra{ background: #dbeafe; color: #1d4ed8; }
.badge-inter{ background: #fef3c7; color: #b45309; }
.badge-intl { background: #dcfce7; color: #166534; }
.dark .badge-intra{ background: rgba(29,78,216,.2);  color: #93c5fd; }
.dark .badge-inter{ background: rgba(180,83,9,.2);   color: #fde68a; }
.dark .badge-intl { background: rgba(22,101,52,.2);  color: #86efac; }

.quick-actions {
  display: flex; flex-wrap: wrap; gap: 7px;
  padding-top: 12px; border-top: 1px solid var(--border); margin-top: 12px;
}
.range-slider { width: 100%; accent-color: var(--brand); margin-top: 5px; cursor: pointer; }

/* ============================================================
   PREVIEW COLUMN
   ============================================================ */
.preview-col {
  display: flex; flex-direction: column; gap: 10px;
  position: sticky; top: 74px;
  max-height: calc(100vh - 94px);
}

.preview-toolbar {
  display: flex; align-items: center; justify-content: space-between; padding: 0 2px;
  flex-shrink: 0;
}
.preview-toolbar-left  { display: flex; align-items: center; gap: 8px; }
.preview-toolbar-right { display: flex; align-items: center; gap: 4px; }
.preview-label { font-size: 11px; font-weight: 700; color: var(--subtle); text-transform: uppercase; letter-spacing: .06em; }
.page-badge    {
  font-size: 10.5px; font-weight: 700;
  background: #e0e7ff; color: #4338ca;
  padding: 2px 8px; border-radius: 100px;
}
.dark .page-badge { background: rgba(67,56,202,.2); color: #a5b4fc; }
.zoom-btn {
  width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-card); color: var(--muted); cursor: pointer;
}
.zoom-btn:hover { background: #f1f5f9; }
.dark .zoom-btn { background: #1e293b; }
.zoom-lbl        { font-size: 12px; font-weight: 600; color: var(--muted); min-width: 40px; text-align: center; }
.zoom-reset-btn  { font-size: 11.5px; color: var(--subtle); background: none; border: none; cursor: pointer; padding: 0 4px; }
.zoom-reset-btn:hover { color: var(--muted); }

/* Paper container */
.paper-bg {
  position: relative;
  background: linear-gradient(180deg, #edf2f7 0%, #dfe9f5 100%);
  border-radius: 16px;
  padding: 22px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  border: 1px solid rgba(148, 163, 184, 0.5);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.7);
}
.dark .paper-bg { background: linear-gradient(180deg, #334155 0%, #1e293b 100%); border-color: rgba(148,163,184,0.35); }

/* Watermark */
.wm-layer {
  position: absolute; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; border-radius: 12px;
  pointer-events: none; user-select: none;
}
#wm-text-display {
  font-size: 3.5rem; font-weight: 900; letter-spacing: .14em;
  text-transform: uppercase; white-space: nowrap; color: rgba(99, 102, 241, 0.13);
}

/* ============================================================
   ████  INVOICE PAPER (SPACIOUS 75% PAGE FILL)  ████
   ============================================================ */
.invoice-paper {
  background: #ffffff;
  border: 1px solid #dfe7f0;
  border-radius: 14px;
  box-shadow: 0 14px 34px rgba(15, 23, 42, 0.12);
  font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
  font-size: 9pt;
  color: #1e293b;
  line-height: 1.55;
  flex-shrink: 0;
  transform-origin: top center;
  min-height: 960px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.paper-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; padding: 18px 24px 16px;
  background: linear-gradient(135deg, #0f172a 0%, #1f2937 35%, #312e81 68%, #4f46e5 100%);
  border-top: 4px solid #818cf8; border-bottom: 1.5px solid rgba(199,210,254,0.8);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.12);
}
.paper-header-left  { display: flex; align-items: flex-start; gap: 14px; flex: 1; min-width: 0; }
.p-logo             { max-height: 60px; max-width: 140px; object-fit: contain; flex-shrink: 0; }
.p-biz-name         { font-size: 13pt; font-weight: 800; color: #ffffff; line-height: 1.25; margin-bottom: 4px; }
.p-biz-sub          { font-size: 8.5pt; color: #e0e7ff; line-height: 1.5; }
.paper-header-right { text-align: right; flex-shrink: 0; }
.p-inv-title        { font-size: 18pt; font-weight: 900; color: #ffffff; letter-spacing: .05em; text-transform: uppercase; line-height: 1.1; }
.p-inv-meta-box     { margin-top: 8px; }
.p-meta-row         { display: flex; justify-content: flex-end; gap: 8px; font-size: 8.5pt; color: #e0e7ff; padding: 2px 0; }
.p-meta-k           { font-weight: 700; color: #c7d2fe; }
.p-meta-v           { font-weight: 700; color: #ffffff; }
.p-tax-badge        { font-size: 7.5pt; font-weight: 700; padding: 3px 8px; border-radius: 100px; }
.p-tax-badge.badge-intra { background: #dbeafe; color: #1d4ed8; }
.p-tax-badge.badge-inter { background: #fef3c7; color: #b45309; }
.p-tax-badge.badge-intl  { background: #dcfce7; color: #166534; }

/* From / Bill To */
.paper-parties       { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1.5px solid #e2e8f0; background: rgba(248,250,252,0.75); }
.party-col           { padding: 16px 26px; }
.party-col-right     { border-left: 1.5px solid #e2e8f0; }
.party-label         { font-size: 7pt; font-weight: 800; color: #64748b; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 5px; }
.party-name          { font-size: 10.5pt; font-weight: 800; color: #0f172a; margin-bottom: 4px; }
.party-text          { font-size: 8.5pt; color: #475569; line-height: 1.55; white-space: pre-line; }
.paper-shipping      { padding: 10px 26px; border-bottom: 1.5px solid #e2e8f0; display: flex; align-items: baseline; gap: 10px; }
.paper-shipping .party-label { white-space: nowrap; flex-shrink: 0; }

/* Items table */
.paper-table-wrap  {
  overflow-x: auto; border-bottom: 1.5px solid #e2e8f0; flex-grow: 0;
}
.paper-table {
  width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed;
}
.paper-thead tr { background: #f1f5f9; }
.pt-sn  { width: 32px; text-align: center; padding: 8px 6px; }
.pt-desc{ text-align: left; padding: 8px 10px; }
.pt-sm  { width: 62px; text-align: center; padding: 8px 6px; }
.pt-num { width: 108px; max-width: 108px; text-align: right; padding: 8px 10px; }
.paper-table thead th {
  font-size: 7.2pt; font-weight: 800; color: #334155;
  text-transform: uppercase; letter-spacing: .05em;
  border: 1px solid #e2e8f0; vertical-align: middle;
  padding-top: 8px; padding-bottom: 8px;
  background: #f8fafc;
}
.paper-table thead th:first-child { border-left: none; }
.paper-table thead th:last-child  { border-right: none; }

/* Expanded item rows */
.paper-table tbody td {
  font-size: 7.9pt; color: #334155;
  padding: 9px 8px; border-right: 1px solid #edf2f7; border-bottom: 1px solid #edf2f7; vertical-align: middle;
  line-height: 1.45;
  background: #ffffff;
  overflow: hidden; text-overflow: ellipsis;
}
.paper-table tbody td:first-child {
  border-left: none; text-align: center; color: #94a3b8; font-weight: 700;
}
.paper-table tbody td.item-name {
  text-align: left; font-weight: 600; color: #0f172a;
  overflow-wrap: anywhere;
}
.paper-table tbody td.item-no,
.paper-table tbody td.item-hsn,
.paper-table tbody td.item-qty,
.paper-table tbody td.item-unit,
.paper-table tbody td.item-tax {
  text-align: center;
}
.paper-table tbody td.item-price,
.paper-table tbody td.item-total,
.paper-table tbody td.money-cell,
.paper-table tfoot td.money-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.paper-table tbody td.item-price,
.paper-table tbody td.item-total {
  width: 108px; max-width: 108px;
}
.paper-table tbody td.item-total,
.paper-table tbody td:last-child {
  font-weight: 700; color: #0f172a;
}
.paper-table tbody tr:nth-child(even) td { background: #fbfcfe; }
.paper-table tbody tr:last-child td { border-bottom: none; }

.paper-tfoot td {
  padding: 10px 8px; font-size: 8.5pt;
  background: #f8fafc; border-top: 2px solid #cbd5e1; color: #0f172a;
  vertical-align: middle;
}
.paper-tfoot td:first-child { border-left: none; }
.paper-tfoot td:last-child  { border-right: none; text-align: right; font-weight: 800; }

.money-cell,
.pf-sum-row span:last-child,
.pf-tax-line span:last-child,
.pf-adv-row span:last-child,
.pf-grand-row span:last-child,
#p-total-amt,
#p-subtotal,
#p-taxable,
#p-grand,
#p-advance,
#p-balance,
#p-disc,
#p-ship,
#p-pkg,
#p-round {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.pf-sum-row span:last-child,
.pf-tax-line span:last-child,
.pf-adv-row span:last-child,
.pf-grand-row span:last-child,
#p-subtotal,
#p-taxable,
#p-grand,
#p-advance,
#p-balance,
#p-disc,
#p-ship,
#p-pkg,
#p-round {
  text-align: right;
  min-width: 0;
  max-width: none;
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Totals footer */
.paper-footer-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  border-bottom: 1.5px solid #e2e8f0;
  margin-top: 0;
}
.pf-left  { padding: 18px 24px; border-right: 1.5px solid #e2e8f0; display: flex; flex-direction: column; }
.pf-right { padding: 18px 24px; display: flex; flex-direction: column; }
.pf-section-label { font-size: 7pt; font-weight: 800; color: #64748b; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
.pf-words-box { margin-bottom: 14px; background: #f8fafc; padding: 8px 10px; border-radius: 6px; border: 1px solid #e2e8f0; }
.pf-words     { font-size: 8.5pt; font-weight: 600; color: #0f172a; line-height: 1.45; }
.pf-bank      { margin-bottom: 12px; }
.pf-bank-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.pf-bank-item { font-size: 8pt; color: #334155; padding: 2px 0; }
.pf-bank-item .k { color: #64748b; font-weight: 600; }
.pf-adv-bal   { margin-top: 10px; padding-top: 8px; border-top: 1px solid #e2e8f0; }
.pf-adv-row   { display: flex; justify-content: space-between; font-size: 8.5pt; color: #334155; padding: 2.5px 0; }

.pf-totals-box {
  background: #f8fafc; border: 1.5px solid #e2e8f0;
  border-radius: 8px; padding: 12px 14px; margin-bottom: 12px;
}
.pf-sum-row   { display: flex; justify-content: space-between; font-size: 8.5pt; color: #475569; padding: 3px 0; }
.pf-sum-row span:first-child { font-weight: 600; }
.pf-tax-line  { display: flex; justify-content: space-between; font-size: 8pt; color: #64748b; padding: 2px 0; }
.pf-grand-row {
  display: flex; justify-content: space-between;
  font-size: 12pt; font-weight: 900; color: #0f172a;
  border-top: 2px solid #cbd5e1; padding-top: 8px; margin-top: 6px;
}
.pf-grand-row span:last-child { color: #4f46e5; }

.pf-sig-block { margin-top: 18px; padding-top: 12px; }
.p-sig-img    { max-height: 50px; max-width: 140px; object-fit: contain; margin-bottom: 6px; }
.p-sig-line   { border-top: 1.5px solid #64748b; padding-top: 6px; }
.pf-notes-text{ font-size: 8pt; color: #475569; white-space: pre-line; line-height: 1.55; }

.paper-footer-bar {
  display: flex; justify-content: space-between;
  padding: 10px 24px; background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border-top: 1.5px solid #c7d2fe; font-size: 7.5pt; color: #64748b;
  font-weight: 500;
}

/* QR */
.qr-canvas-box {
  display: inline-block; border: 1px solid #e2e8f0;
  border-radius: 6px; padding: 6px; background: #fff; margin-top: 4px;
}
#qr-canvas canvas, #qr-canvas img { width: 85px !important; height: 85px !important; }
.qr-empty-state {
  width: 85px; height: 85px; display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 7pt; font-weight: 700; line-height: 1.45;
  color: #64748b; background: repeating-linear-gradient(45deg, #f8fafc, #f8fafc 5px, #f1f5f9 5px, #f1f5f9 10px);
}

/* Fixed desktop layout used only while building the PDF download image.
   Width is intentionally NOT hardcoded here — app.js sets it inline per
   the selected page size (A4 / Letter / A5 / Legal) so the export always
   matches what's chosen in the preview toolbar. */
.pdf-capture {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
  transform: none !important;
  margin: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}
.pdf-capture .paper-parties { grid-template-columns: 1fr 1fr !important; }
.pdf-capture .paper-footer-grid {
  grid-template-columns: 1fr 1fr !important;
  margin-top: 0 !important;
}
.pdf-capture .paper-table-wrap { flex-grow: 0 !important; overflow: hidden !important; }
.pdf-capture .pf-left,
.pdf-capture .pf-right { padding: 18px 24px !important; }
.pdf-capture .party-col { padding: 16px 26px !important; }
.pdf-capture .paper-shipping { padding: 10px 26px !important; }

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.dark ::-webkit-scrollbar-track { background: #1e293b; }
.dark ::-webkit-scrollbar-thumb { background: #475569; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) {
  .preview-col { position: static; max-height: none; }
  .paper-bg { max-height: 640px; }
}
@media (max-width: 768px) {
  body { overflow-x: hidden; }
  #main-nav { position: sticky; }
  .nav-inner { height: auto; min-height: 56px; padding: 8px 10px; gap: 7px; flex-wrap: wrap; }
  .nav-brand { margin-right: auto; }
  .brand-title { font-size: 15px; }
  .brand-domain { display: none; }
  .mode-tabs { order: 3; width: 100%; }
  .mode-tab { flex: 1; padding: 7px 8px; text-align: center; }
  .nav-actions { order: 4; width: calc(100% + 20px); margin: 0 -10px; padding: 8px 10px 3px; overflow-x: auto; gap: 7px; border-top: 1px solid var(--border); scrollbar-width: none; }
  .nav-actions::-webkit-scrollbar { display: none; }
  .nav-btn, .nav-icon-btn, .nav-select { flex-shrink: 0; }
  .nav-btn { min-height: 36px; padding: 0 10px; }
  .nav-select { height: 36px; }
  .nav-icon-btn { width: 36px; height: 36px; }
  .dropdown-wrap { display: none; }
  .app-main { padding: 8px; gap: 12px; }
  .editor-col { gap: 10px; }
  .workspace-banner { padding: 15px; border-radius: 13px; }
  .workspace-banner h1 { font-size: 16px; }
  .workspace-status { display: none; }
  .workspace-banner p:last-child { font-size: 11px; }
  .form-card { border-radius: 13px; }
  .card-head { min-height: 50px; padding: 11px 12px; }
  .card-title { font-size: 12.5px; }
  .card-head-right .chip-btn { display: none; }
  .card-body { padding: 12px 10px; }
  .upload-grid, .field-grid, .charges-row { grid-template-columns: 1fr; gap: 9px; }
  .field-span-2 { grid-column: span 1; }
  #india-biz-fields { grid-template-columns: 1fr !important; }
  .field-grid > div:not(.field-grid) { padding: 6px; }
  .finput { min-height: 39px; font-size: 16px; }
  textarea.finput { min-height: 66px; }
  .upload-box { height: 64px; }
  .items-tbl { min-width: 650px; }
  .table-scroll { margin: 0 -12px; padding: 0 12px 4px; }
  .add-item-btn { width: 100%; justify-content: center; min-height: 42px; }
  .charges-row { border-top: 0; margin-top: 4px; }
  .totals-summary { padding: 11px 12px; }
  .preview-col { gap: 8px; min-width: 0; }
  .preview-toolbar { padding: 7px 5px; min-height: 42px; }
  .preview-toolbar-right { gap: 4px; }
  .preview-label { font-size: 10px; letter-spacing: .04em; }
  .zoom-reset-btn { min-width: 38px; }
  .paper-bg {
    min-height: 480px; max-height: 72vh; padding: 10px 6px;
    border-radius: 11px; overflow: auto; overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  /* Keep the invoice document intact; only the editor becomes single-column. */
  .invoice-paper { min-width: 595px; }
  .paper-footer-grid { grid-template-columns: 1fr 1fr; }
  .pf-left { border-right: 1.5px solid #e2e8f0; border-bottom: 0; }
  .paper-parties { grid-template-columns: 1fr 1fr; }
  .party-col-right { border-left: 1.5px solid #e2e8f0; border-top: 0; }
  .mode-tabs .mode-tab { font-size: 10.5px; padding: 7px 8px; }
  .paper-bg     { padding: 10px 6px; }
  .charges-row  { grid-template-columns: 1fr 1fr; }
  .history-stats { grid-template-columns: repeat(2, 1fr); }
  .modal-box { max-height: 90vh; }
}

@media (max-width: 390px) {
  .brand-kite { font-size: 19px; }
  .brand-title { font-size: 14px; }
  .workspace-banner h1 { font-size: 15px; }
  .card-title { font-size: 12px; }
  .charges-row { grid-template-columns: 1fr; }
  .paper-bg { max-height: 68vh; }
}

/* ============================================================
   PRINT
   ============================================================ */
@media print {
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
  }
  .no-print     { display: none !important; }
  .app-main     { display: block !important; padding: 0 !important; margin: 0 !important; }
  .editor-col   { display: none !important; }
  .preview-col  { width: 100% !important; position: static !important; max-height: none !important; }
  .preview-toolbar { display: none !important; }
  .paper-bg {
    background: #fff !important;
    padding: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    border-radius: 0 !important;
    display: block !important;
    border: 0 !important;
    box-shadow: none !important;
  }
  .wm-layer     { position: fixed !important; inset: 0 !important; border-radius: 0 !important; }
  /* IMPORTANT: no fixed height and no overflow:hidden here. A forced
     297mm height with clipped overflow was cutting off any invoice with
     enough items/notes to run past one page. Instead the paper's true
     physical width is set dynamically by setPageSize() in app.js (per
     the selected page size), and height is left natural so the browser
     paginates a long invoice across multiple printed pages correctly,
     the same way Word/Vyapar-style documents do. */
  .invoice-paper {
    box-shadow: none !important;
    min-height: 0 !important;
    height: auto !important;
    transform: none !important;
    margin: 0 auto !important;
    border: 0 !important;
    border-radius: 0 !important;
    overflow: visible !important;
  }
  /* Keep individual rows/sections from being sliced in half across a
     page break, without preventing the document itself from spanning
     multiple pages. */
  .paper-header,
  .paper-parties,
  .paper-footer-grid,
  .paper-footer-bar,
  .paper-table tbody tr,
  .paper-thead {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  .paper-header {
    background: linear-gradient(135deg, #172554 0%, #312e81 55%, #4f46e5 100%) !important;
    border-top-color: #818cf8 !important;
  }
  .paper-table-wrap { overflow: visible !important; }
  .paper-thead tr { background: #f1f5f9 !important; }
  .paper-tfoot td { background: #f8fafc !important; }
  .pf-totals-box  { background: #f8fafc !important; }
  .paper-footer-bar { background: #f8fafc !important; }
  /* Fallback only — setPageSize() injects the live, size-accurate
     @page rule into <head> at load and whenever the page size changes. */
  @page { margin: 0; }
}