:root {
  --navy: #10284A;
  --navy2: #11294B;
  --orange: #F5A623;
  --orange-dark: #E8940E;
  --bg: #F5F7FA;
  --white: #FFFFFF;
  --border: #D9E1EA;
  --success: #0F9B6B;
  --success-bg: #E8F8F1;
  --error: #C0392B;
  --error-bg: #FBEAE8;
  --text: #10284A;
  --muted: #5A6B85;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(16,40,74,0.08);
  --font-heading: Georgia, 'Times New Roman', serif;
  --font-body: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
h1, h2, h3, h4 { font-family: var(--font-heading); margin: 0; }
a { color: var(--orange-dark); }
.hidden { display: none !important; }

/* ===================== HEADER ===================== */
.app-header {
  background: var(--navy);
  border-bottom: 1px solid var(--navy2);
}
.app-header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-name {
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  letter-spacing: 0.5px;
}
.brand-sub { font-size: 12px; color: rgba(255,255,255,0.55); }

.app-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.7);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  transition: all 0.15s;
}
.nav-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-btn.active { background: var(--orange); color: var(--navy); }

/* ===================== MAIN ===================== */
.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px 60px;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.empty-state-icon { font-size: 40px; margin-bottom: 14px; }
.empty-state h2 { font-size: 20px; margin-bottom: 8px; }
.empty-state p { color: var(--muted); }

/* ===================== PANEL / CARD ===================== */
.panel-card, .section-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.panel-card-head { margin-bottom: 18px; }
.panel-card-head h2 { font-size: 20px; margin-bottom: 4px; }
.panel-card-sub { color: var(--muted); font-size: 13px; }

.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.section-num {
  width: 24px; height: 24px;
  background: var(--navy);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  font-family: var(--font-body);
  flex-shrink: 0;
}
.section-head h3 { font-size: 15px; }

/* ===================== FORM FIELDS ===================== */
.field-grid { display: grid; gap: 14px; margin-bottom: 14px; }
.field-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.field-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.field-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
  .field-grid.cols-2, .field-grid.cols-3, .field-grid.cols-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .field-grid.cols-2, .field-grid.cols-3, .field-grid.cols-4 { grid-template-columns: 1fr; }
}

.field { display: flex; flex-direction: column; }
.field label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}
.field .req { color: var(--error); }
.field input, .field select {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font-body);
  outline: none;
  transition: border-color 0.15s;
}
.field input:focus, .field select:focus { border-color: var(--orange); }
.field input.readonly-input { background: var(--bg); color: var(--muted); cursor: not-allowed; }
.field-hint { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.field-error {
  font-size: 11.5px;
  color: var(--error);
  margin-top: 4px;
  min-height: 14px;
  display: block;
}
.field.has-error input, .field.has-error select { border-color: var(--error); }

.input-with-select { display: flex; gap: 6px; }
.input-with-select input { flex: 1; }
.input-with-select select { width: 68px; }

/* Toggle switch */
.switch-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  position: relative;
}
.switch-label input {
  position: absolute;
  width: 36px;
  height: 20px;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}
.switch-label input:focus-visible + .switch-track {
  outline: 2px solid var(--orange);
  outline-offset: 2px;
}
.switch-track {
  width: 36px; height: 20px;
  background: var(--border);
  border-radius: 20px;
  position: relative;
  transition: background 0.15s;
  flex-shrink: 0;
}
.switch-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.switch-label input:checked + .switch-track { background: var(--orange); }
.switch-label input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
.field-inline-toggle { margin-bottom: 14px; }

.tax-treatment-note {
  font-size: 12px;
  padding: 9px 13px;
  border-radius: var(--radius-sm);
  margin-top: 4px;
}
.tax-treatment-note.intra { background: var(--success-bg); color: var(--success); }
.tax-treatment-note.inter { background: #EAF1FE; color: #1A73E8; }
.tax-treatment-note.unknown { background: #FEF6E4; color: var(--orange-dark); }

/* ===================== BUTTONS ===================== */
.btn {
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--navy2); }
.btn-ghost { background: var(--white); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 7px 12px; font-size: 12px; }
.panel-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.save-confirm { color: var(--success); font-size: 13px; font-weight: 700; }

/* ===================== BUILDER TOOLBAR ===================== */
.builder-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.toolbar-spacer { flex: 1; }
.supplier-missing-warning {
  font-size: 12.5px;
  color: var(--orange-dark);
  font-weight: 600;
}

/* ===================== BUILDER GRID ===================== */
.builder-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 1100px) {
  .builder-grid { grid-template-columns: 1fr; }
}

/* ===================== ITEMS TABLE ===================== */
.items-table-wrap { overflow-x: auto; }
.items-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.items-table th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 6px;
  border-bottom: 2px solid var(--border);
}
.items-table td {
  padding: 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.items-table input, .items-table select {
  width: 100%;
  padding: 6px 7px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12.5px;
  font-family: var(--font-body);
}
.col-sno { width: 28px; text-align: center; font-size: 12px; color: var(--muted); padding-top: 12px; }
.col-qty input, .col-rate input, .col-gst select, .col-cess input { width: 64px; }
.col-unit input { width: 56px; }
.col-disc { min-width: 110px; }
.col-total { text-align: right; font-weight: 700; white-space: nowrap; padding-top: 10px; font-size: 12.5px; }
.col-actions { width: 30px; }
.row-delete-btn {
  background: none; border: none; color: var(--error);
  cursor: pointer; font-size: 15px; padding: 4px;
}
.discount-inline { display: flex; gap: 4px; }
.discount-inline input { width: 50px; }
.discount-inline select { width: 46px; }

/* ===================== VALIDATION SUMMARY ===================== */
.validation-summary {
  background: var(--error-bg);
  border: 1px solid rgba(192,57,43,0.25);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.validation-summary h4 { color: var(--error); font-size: 13px; margin-bottom: 8px; }
.validation-summary ul { margin: 0; padding-left: 18px; color: var(--error); font-size: 12.5px; }

/* ===================== LIVE PREVIEW ===================== */
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.preview-label { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.preview-frame {
  background: #E8EBF0;
  border-radius: var(--radius);
  padding: 16px;
  max-height: 900px;
  overflow-y: auto;
}

.invoice-sheet {
  background: #fff;
  padding: 32px;
  min-height: 500px;
  box-shadow: 0 2px 10px rgba(16,40,74,0.12);
  font-size: 12px;
  color: var(--text);
}
.inv-header { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 16px; border-bottom: 2px solid var(--navy); margin-bottom: 16px; }
.inv-supplier-name { font-family: var(--font-heading); font-size: 18px; font-weight: 700; color: var(--navy); margin-bottom: 4px; }
.inv-supplier-details { color: var(--muted); font-size: 11.5px; line-height: 1.6; }
.inv-doc-type {
  display: inline-block;
  background: var(--navy);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 14px;
  border-radius: 4px;
  margin-bottom: 8px;
  letter-spacing: 0.03em;
}
.inv-meta { text-align: right; font-size: 11.5px; }
.inv-meta-row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 3px; }
.inv-meta-label { color: var(--muted); }
.inv-meta-value { font-weight: 700; }

.inv-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 18px; }
.inv-party-label { font-size: 10.5px; font-weight: 700; color: var(--orange-dark); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.inv-party-name { font-weight: 700; margin-bottom: 3px; }
.inv-party-details { color: var(--muted); font-size: 11px; line-height: 1.6; }

.inv-items-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.inv-items-table th {
  background: var(--navy);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 7px 6px;
  text-align: left;
}
.inv-items-table th.num, .inv-items-table td.num { text-align: right; }
.inv-items-table td {
  padding: 6px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}

.inv-totals-wrap { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.inv-totals { width: 280px; }
.inv-totals-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 11.5px; }
.inv-totals-row.grand {
  border-top: 2px solid var(--navy);
  margin-top: 6px;
  padding-top: 8px;
  font-weight: 700;
  font-size: 13.5px;
  color: var(--navy);
}

.inv-words {
  background: var(--bg);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 11.5px;
  font-style: italic;
  margin-bottom: 16px;
}

.inv-empty-note {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  font-size: 13px;
}

/* ===================== FOOTER ===================== */
.app-footer {
  text-align: center;
  padding: 20px 24px 30px;
  font-size: 11px;
  color: var(--muted);
  max-width: 900px;
  margin: 0 auto;
  line-height: 1.6;
}

/* ===================== PRINT ===================== */
@media print {
  body * { visibility: hidden; }
  .invoice-sheet, .invoice-sheet * { visibility: visible; }
  .invoice-sheet {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    box-shadow: none;
    padding: 10mm;
  }
  @page { size: A4; margin: 10mm; }

  /* Multi-page invoices: repeat the item table's header row on every
     printed page (standard, well-supported table pagination behaviour -
     no JS needed) and never split a single item row across a page break. */
  .inv-items-table thead { display: table-header-group; }
  .inv-items-table tr { page-break-inside: avoid; break-inside: avoid; }

  /* Keep these blocks intact rather than splitting mid-block, so the
     signature image is never cut off, payment details stay readable
     together, and terms don't visually overlap the next page. */
  .inv-totals-wrap, .inv-payment-section, .inv-terms, .inv-signature-block {
    page-break-inside: avoid;
    break-inside: avoid;
  }
}

/* ===================== PHASE 2: UPLOAD BOXES ===================== */
.upload-box {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 8px;
}
.upload-box-sm { height: 70px; }
.upload-preview { max-width: 100%; max-height: 100%; object-fit: contain; }
.upload-placeholder { font-size: 12px; color: var(--muted); }
.upload-actions { display: flex; gap: 8px; }

/* ===================== PHASE 2: TERMS TEXTAREA ===================== */
.terms-textarea, textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-body);
  resize: vertical;
  outline: none;
  width: 100%;
}
.terms-textarea:focus, textarea:focus { border-color: var(--orange); }

/* ===================== PHASE 2: BANK ACCOUNT CARDS ===================== */
.bank-account-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.bank-account-card.is-default { border-color: var(--orange); background: #FFFBF2; }
.bank-account-info { font-size: 12.5px; line-height: 1.6; }
.bank-account-info .bank-name { font-weight: 700; font-size: 14px; color: var(--navy); }
.bank-account-info .muted { color: var(--muted); }
.default-badge {
  display: inline-block;
  background: var(--orange);
  color: var(--navy);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  margin-left: 8px;
}
.bank-account-actions { display: flex; gap: 6px; flex-shrink: 0; }
.empty-state-inline { text-align: center; padding: 30px; color: var(--muted); font-size: 13px; }

/* ===================== PHASE 2: PAYMENT TOGGLES ===================== */
.payment-toggle-row {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  margin: 12px 0;
}

/* ===================== PHASE 2: INPUT WITH BUTTON (show/hide account number) ===================== */
.input-with-btn { display: flex; gap: 6px; }
.input-with-btn input { flex: 1; }

/* ===================== PHASE 2: MODAL ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(16,40,74,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; }
.modal-close {
  background: none; border: none; font-size: 22px; line-height: 1;
  color: var(--muted); cursor: pointer; padding: 0 4px;
}
.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ===================== PHASE 2: PREVIEW ADDITIONS ===================== */
.inv-logo { max-width: 140px; max-height: 70px; object-fit: contain; margin-bottom: 8px; }
.inv-payment-section {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-bottom: 16px;
}
.inv-section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.inv-payment-grid { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.inv-payment-details { font-size: 11px; line-height: 1.8; }
.inv-payment-details .label { color: var(--muted); display: inline-block; width: 90px; }
.inv-qr-img { width: 80px; height: 80px; object-fit: contain; border: 1px solid var(--border); padding: 4px; }
.inv-terms { font-size: 10.5px; color: var(--muted); line-height: 1.7; margin-bottom: 16px; }
.inv-terms ol { margin: 4px 0 0; padding-left: 18px; }
.inv-signature-block { display: flex; justify-content: flex-end; margin-top: 20px; }
.inv-signature-inner { text-align: center; }
.inv-signature-img { max-width: 120px; max-height: 50px; object-fit: contain; display: block; margin: 0 auto 4px; }
.inv-signature-line { border-top: 1px solid var(--text); width: 160px; margin: 20px auto 4px; }

/* ===================== PHASE 3: DASHBOARD ===================== */
.dashboard-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.dashboard-kpi-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.dashboard-kpi-label { font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.dashboard-kpi-value { font-family: var(--font-heading); font-size: 22px; font-weight: 700; color: var(--navy); }

/* ===================== PHASE 3: STATUS BADGES ===================== */
.status-badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.status-Draft { background: #EEF1F5; color: var(--muted); }
.status-Issued { background: #EAF1FE; color: #1A73E8; }
.status-Paid { background: var(--success-bg); color: var(--success); }
.status-Partially.Paid, .status-Partially-Paid { background: #FEF6E4; color: var(--orange-dark); }
.status-Overdue { background: var(--error-bg); color: var(--error); }
.status-Cancelled { background: #EEF1F5; color: var(--muted); text-decoration: line-through; }

/* ===================== PHASE 3: INVOICES LIST ===================== */
.invoices-toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.invoices-toolbar input, .invoices-toolbar select {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; font-family: var(--font-body);
}
.invoices-toolbar input { flex: 1; min-width: 180px; }
.invoices-list-table { width: 100%; border-collapse: collapse; }
.invoices-list-table th {
  text-align: left; font-size: 10.5px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.03em; padding: 8px 10px; border-bottom: 2px solid var(--border);
}
.invoices-list-table th.num, .invoices-list-table td.num { text-align: right; }
.invoices-list-table td { padding: 10px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.invoices-list-table .row-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.invoices-list-table .row-actions button {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 11.5px; font-weight: 700; padding: 3px 6px; border-radius: 4px;
}
.invoices-list-table .row-actions button:hover { background: var(--bg); color: var(--navy); }
.invoices-list-table .row-actions button.danger:hover { color: var(--error); }

/* ===================== PHASE 3: CUSTOMERS LIST ===================== */
.customer-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.customer-card-info { font-size: 12.5px; line-height: 1.6; }
.customer-card-info .cust-name { font-weight: 700; font-size: 14px; color: var(--navy); }
.customer-card-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ===================== PHASE 3: MISC ===================== */
.editing-badge {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--orange-dark);
  background: #FEF6E4;
  padding: 5px 10px;
  border-radius: 10px;
}
.readonly-value-display {
  padding: 9px 11px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-weight: 700;
  color: var(--navy);
}
