:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #5f6b80;
  --line: #cdd7e5;
  --blue: #1459b8;
  --blue-dark: #0d3f82;
  --green: #16835a;
  --gold: #c2891f;
  --red: #b42318;
  --soft-blue: #eaf2ff;
  --soft-gold: #fff6df;
  --tint: #f7faff;
  --shadow: 0 10px 26px rgba(22, 38, 70, 0.10);
  /* Compact, mobile-first type & spacing scale. */
  --fs-xs: 11px;
  --fs-sm: 12px;
  --fs-label: 13px;
  --fs-md: 14px;
  --fs-base: 15px;
  --fs-lg: 16px;
  --fs-xl: 18px;
  --fs-title: 21px;
  --fs-header: 22px;
  --ctrl-h: 42px;
}

/* Dark theme — only the palette flips; the header keeps its brand blue and the
   printed/PDF quotation always stays light (see .quote-print / @media print). */
:root[data-theme="dark"] {
  --bg: #0f1722;
  --panel: #1b2433;
  --ink: #e7edf6;
  --muted: #9fb0c9;
  --line: #2e3b4e;
  --blue: #2f6fd0;
  --blue-dark: #6aa6ff;
  --green: #2a9d6e;
  --gold: #d9a83c;
  --red: #e0796d;
  --soft-blue: #1b3252;
  --soft-gold: #3a2f12;
  --tint: #16202c;
  --shadow: 0 10px 26px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

/* The [hidden] attribute must always win, even over flex/grid display rules
   (e.g. .form-field { display:flex }) used to lay the form out. */
[hidden] {
  display: none !important;
}

html {
  height: 100%;
}

/* App-shell: header + tabs are a fixed top, the content scrolls inside
   .scroll-area only — so nothing slides under the status bar (top) or the
   navigation bar (bottom). */
body {
  height: 100%;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
  background: var(--bg);
  /* Roboto is the native Android font; falls back to the platform sans on web. */
  font-family: Roboto, "Noto Sans", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: var(--fs-base);
  line-height: 1.35;
}

/* Inline icon (monochrome, inherits text colour). */
.icon {
  width: 1.15em;
  height: 1.15em;
  flex: 0 0 auto;
  vertical-align: -0.18em;
}

.page-header {
  flex: 0 0 auto;
}

.scroll-area {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 22px 11px;
  background: linear-gradient(90deg, #0d3f82, #1459b8);
  color: white;
}

.page-header h1 {
  margin: 0 0 2px;
  font-size: var(--fs-header);
  line-height: 1.2;
}

.page-header p {
  margin: 0;
  color: #d8e7ff;
  font-size: 13px;
}

.header-details {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 560px;
}

.header-details span:not(:empty) {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 4px 9px;
  background: rgba(255, 255, 255, 0.12);
  color: white;
  font-size: 12px;
}

.pages,
.app-footer {
  width: min(1320px, calc(100% - 28px));
  margin-left: auto;
  margin-right: auto;
}

/* ===================== Pages ===================== */
.pages {
  padding: 14px 0 26px;
}

.page {
  display: none;
}

.page.is-active {
  display: block;
}

.page-tools,
.summary-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 4px 0 12px;
}

.summary-tools {
  margin-top: 12px;
}

/* Preview-screen toolbars match the sticky action strips: same button shape,
   icon size and colour priorities (Save → green · Print → dark · Share → blue
   · WhatsApp → green · Edit / Back → plain outline). */
.summary-tools button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  min-width: 96px;
  padding: 7px 12px;
  font-weight: 700;
  font-size: 14px;
}
.summary-tools .icon { width: 17px; height: 17px; }
#saveCashMemoButton,
#whatsappCashMemoButton {
  border-color: var(--green);
  background: var(--green);
  color: white;
}
#shareCashMemoButton,
#invoiceQuoteButton {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
}
#printCashMemoButton {
  border-color: #1f2a44;
  background: #1f2a44;
  color: white;
}

.inline-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.inline-field .toolbar-select {
  min-height: 38px;
}

.toolbar {
  display: none;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.quote-title {
  margin-top: 14px;
  margin-bottom: 10px;
  font-size: var(--fs-title);
}

.section-heading {
  margin-top: 18px;
  margin-bottom: 10px;
  font-size: 22px;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.toolbar-select {
  min-height: 36px;
  width: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--panel);
}

/* Bottom dock: a fixed app-shell bar (always visible above the nav bar) holding
   the contextual actions and, on mobile, the cart line. */
.bottom-dock {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(22, 38, 70, 0.08);
}

.bottom-dock[hidden] {
  display: none;
}

.bottom-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding: 8px max(14px, calc((100% - 1100px) / 2));
}

/* The inactive action group (Quote vs Summary) must stay hidden — needed
   because .bottom-actions display:flex would otherwise beat [hidden]. */
.bottom-actions[hidden] {
  display: none;
}

.bottom-actions:not(.action-strip) {
  justify-content: flex-end;
}

.action-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.form-actions {
  justify-content: flex-end;
  margin-left: auto;
}

.manage-actions button {
  min-width: 92px;
}

.form-actions button {
  min-width: 96px;
}

.bottom-actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 7px 12px;
  font-weight: 700;
  font-size: 14px;
}

.bottom-actions .icon { width: 17px; height: 17px; }

/* The cart line is mobile-only (see the media query below). */
.cart-bar {
  display: none;
}

/* Action-bar button priorities:
   Preview → blue · Save → green (primary) · Print → dark · Share → green
   New / Clear → plain outline · Back → grey outline */
.bottom-actions #previewButton,
.bottom-actions #previewCashMemoButton {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
  font-weight: 700;
}

.bottom-actions #saveQuoteButton,
.bottom-actions #shareQuoteButton {
  border-color: var(--green);
  background: var(--green);
  color: white;
  font-weight: 700;
}

.bottom-actions #printQuoteButton {
  border-color: #1f2a44;
  background: #1f2a44;
  color: white;
  font-weight: 700;
}

.bottom-actions #backToQuoteButton {
  border-color: var(--line);
  background: var(--panel);
  color: var(--muted);
}

button:hover {
  border-color: var(--blue);
}

#saveQuoteButton,
#printQuoteButton,
form button[type="submit"] {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
  font-weight: 700;
}

#shareQuoteButton {
  border-color: var(--green);
  background: var(--green);
  color: white;
  font-weight: 700;
}

#settingsButton,
#saveSettingsButton {
  border-color: var(--gold);
  background: var(--gold);
  color: white;
  font-weight: 700;
}

#clearHistoryButton {
  border-color: var(--red);
  color: var(--red);
}

.settings-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 0;
}

.hint {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.settings-currency-table {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel);
  table-layout: fixed;
  font-size: 14px;
}

.settings-currency-table th:nth-child(1),
.settings-currency-table td:nth-child(1) {
  width: 110px !important;
}

.settings-currency-table th:nth-child(3),
.settings-currency-table td:nth-child(3) {
  width: 92px !important;
}

.settings-currency-table th {
  padding: 7px 10px;
  background: var(--soft-blue);
  color: var(--blue-dark);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.2;
}

.settings-currency-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
}

.settings-currency-table tr:last-child td {
  border-bottom: 0;
}

.settings-currency-table input {
  height: 32px;
  min-height: 32px;
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 14px;
}

.settings-currency-table .removeSettingCurrency {
  min-height: 32px;
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 13px;
}

#addSettingCurrencyButton {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 14px;
}

fieldset {
  margin: 12px 0;
  padding: 12px 14px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--soft-blue);
  color: var(--blue-dark);
  font-weight: 700;
  font-size: var(--fs-lg);
}

legend .icon { width: 16px; height: 16px; }

fieldset:nth-of-type(2) legend,
fieldset:nth-of-type(4) legend {
  background: var(--soft-gold);
  color: #805300;
}

table {
  border-collapse: collapse;
}

td {
  vertical-align: middle;
}

.rowInrValue {
  color: var(--green);
}

.exception-cell label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--gold);
}

/* ===== Compact 2-column quote form (mobile-first card layout) ===== */
#quoteForm,
#cashMemoForm {
  width: 100%;
  max-width: none;
}
.section-card { padding: 10px 12px 12px; margin: 8px 0; }
.form-stepper {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 12px;
}
.form-step {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--blue-dark);
  font-weight: 800;
  font-size: 13px;
}
.form-step.is-active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}
.section-card[hidden],
.form-step-controls[hidden] {
  display: none !important;
}
.form-step-controls {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 0 82px;
}
.form-step-controls button {
  min-width: 112px;
}
.form-step-controls button:last-child {
  margin-left: auto;
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 800;
}

.form-grid { display: grid; grid-template-columns: 1fr; gap: 8px 10px; }
.form-grid.two-col { grid-template-columns: 1fr 1fr; }
.form-grid.three-col { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid.four-col { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid.five-col { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.form-grid.six-col { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.compact-customer-grid { align-items: end; }
.compact-line-grid { align-items: end; }
.compact-address-grid { align-items: start; }
.compact-address-grid .address-field { grid-column: span 3; }
.compact-charges-grid { align-items: end; }
.compact-charges-grid .compact-hint {
  grid-column: 1 / -1;
  margin-top: -2px;
}
.compact-payment-grid { align-items: end; }
.compact-payment-grid .payment-remarks-field { grid-column: span 2; }
.form-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-field.full { grid-column: 1 / -1; }
.form-label { margin: 0; font-size: 12px; font-weight: 700; color: var(--muted); }

#quoteForm input,
#quoteForm select,
#quoteForm textarea,
#cashMemoForm input,
#cashMemoForm select,
#cashMemoForm textarea {
  height: 36px;
  min-height: 36px;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 9px;
}
#quoteForm textarea,
#cashMemoForm textarea {
  height: auto;
}
#quoteForm .field-hint { margin-top: 2px; }

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}
.exception-cell .inline-check { color: var(--gold); }
.exception-cell input[type="text"] {
  margin-top: 8px;
  max-width: 520px;
}

/* Forex Details — each currency row is a compact card */
.forex-rows { display: flex; flex-direction: column; gap: 10px; }
.forex-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--tint);
}
.forex-row-foot { grid-template-columns: 3fr 2fr; align-items: end; }
.forex-row .rowInrValue { padding: 8px 0 0; font-size: 15px; font-weight: 800; color: var(--green); }
.forex-row .removeCurrencyRow { width: 100%; min-height: 40px; }
.forex-actions { margin-top: 12px; }

/* Read-only amount box (e.g. live Grand Total beside Tendered Amount) */
.amount-display {
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--tint);
  font-size: 15px;
  font-weight: 800;
  color: var(--blue-dark);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Live "Allowed / Not allowed" status pill beside Payment Mode. */
.pm-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--tint);
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
}
.pm-status.is-ok { background: rgba(22, 131, 90, 0.12); border-color: var(--green); color: var(--green); }
.pm-status.is-bad { background: rgba(180, 35, 24, 0.12); border-color: var(--red); color: var(--red); }

@media (min-width: 1000px) {
  #page-quote #quoteForm,
  #page-cashmemo #cashMemoForm {
    display: block;
  }

  #page-quote .section-card,
  #page-cashmemo .section-card {
    margin: 10px 0;
  }

  #page-quote .form-grid.two-col,
  #page-cashmemo .form-grid.two-col {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  #page-quote .form-grid.three-col,
  #page-cashmemo .form-grid.three-col {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
  }

  #page-quote .form-grid.four-col,
  #page-cashmemo .form-grid.four-col {
    grid-template-columns: repeat(4, minmax(130px, 1fr));
  }

  #page-quote .form-grid.five-col,
  #page-cashmemo .form-grid.five-col {
    grid-template-columns: repeat(5, minmax(115px, 1fr));
  }

  #page-quote .form-grid.six-col,
  #page-cashmemo .form-grid.six-col {
    grid-template-columns: repeat(6, minmax(105px, 1fr));
  }

  #page-quote #forexRows,
  #page-cashmemo #cashForexRows {
    gap: 8px;
  }

  #page-quote .forex-row,
  #page-cashmemo .forex-row {
    display: grid;
    grid-template-columns: minmax(120px, 0.9fr) minmax(180px, 1.25fr) minmax(130px, 0.85fr) minmax(110px, 0.75fr) minmax(115px, 0.75fr) minmax(100px, 0.7fr);
    gap: 8px;
    align-items: end;
    padding: 10px;
  }

  #page-quote .forex-row > .form-grid,
  #page-cashmemo .forex-row > .form-grid {
    display: contents;
  }

  #page-quote .forex-row-foot,
  #page-cashmemo .forex-row-foot {
    display: contents;
  }

  #page-quote .forex-row .rowInrValue,
  #page-cashmemo .forex-row .cashRowInrValue {
    display: flex;
    align-items: center;
    min-height: 36px;
    padding: 0;
  }

  #page-quote .forex-row .removeCurrencyRow,
  #page-cashmemo .forex-row .cashRemoveCurrencyRow {
    min-height: 36px;
  }

  #page-quote input,
  #page-quote select,
  #page-cashmemo input,
  #page-cashmemo select {
    height: 36px;
    min-height: 36px;
  }
}

@media (max-width: 760px) {
  .form-grid.three-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .form-grid.four-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .form-grid.five-col,
  .form-grid.six-col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .compact-customer-grid .form-field:first-child {
    grid-column: 1 / -1;
  }
  .compact-address-grid .address-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  .form-grid.two-col,
  .form-grid.three-col,
  .form-grid.four-col,
  .form-grid.five-col,
  .form-grid.six-col,
  .pm-grid,
  .forex-row-foot {
    grid-template-columns: 1fr;
  }
  .compact-address-grid .address-field {
    grid-column: 1;
  }
  .compact-payment-grid .payment-remarks-field {
    grid-column: 1;
  }
}

@media (max-width: 360px) {
  .form-grid.two-col { column-gap: 8px; }
  #quoteForm input,
  #quoteForm select { font-size: 13px; padding: 6px 8px; }
}

/* Compliance violations shown inline at the top of the Summary so they're
   visible while previewing (Save also hard-blocks via the popup). */
.compliance-warning {
  margin-bottom: 12px;
  padding: 10px 14px;
  border: 1px solid var(--red);
  border-left: 4px solid var(--red);
  border-radius: 8px;
  background: #fdecec;
  color: var(--red);
}

.compliance-warning strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.compliance-warning ul {
  margin: 0;
  padding-left: 18px;
}

.compliance-warning li {
  margin: 3px 0;
  font-weight: 600;
}

.compliance-popup {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 14vh;
  background: rgba(22, 38, 70, 0.35);
}

.compliance-popup-card {
  width: calc(100% - 32px);
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--red);
  border-top: 4px solid var(--red);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 18px 20px;
}

.compliance-popup-card strong {
  color: var(--red);
  font-size: 15px;
}

.compliance-popup-card ul {
  margin: 10px 0 14px;
  padding-left: 20px;
  color: var(--ink);
}

.compliance-popup-card li {
  margin: 6px 0;
}

.compliance-popup-close {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: white;
  border-radius: 6px;
  padding: 6px 18px;
  cursor: pointer;
}

/* Workflow modals (Confirm Save, Saved success, Discard preview). */
/* Center tall modals and let the card scroll internally so the bottom buttons
   (e.g. "Add") are always reachable on short screens. */
.app-modal { align-items: center; padding-top: 0; }
.app-modal-card { text-align: left; max-height: 88vh; overflow-y: auto; }
.app-modal-msg { margin: 8px 0 14px; color: var(--muted); font-size: 14px; line-height: 1.45; }
.app-modal-msg strong { color: var(--ink); }
.app-modal-label {
  display: block;
  margin: 10px 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.app-modal-input {
  width: 100%;
  min-height: 82px;
}
.app-modal-error {
  margin: 6px 0 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}
.app-modal-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.app-modal-actions button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  flex: 1 1 auto; min-width: 90px; min-height: 42px; padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--ink); font-weight: 700; font-size: 14px; cursor: pointer;
}
.app-modal-actions .icon { width: 17px; height: 17px; }
.app-modal-actions .primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.app-modal-actions .btn-green { background: var(--green); border-color: var(--green); color: #fff; }
.app-modal-actions .btn-dark { background: #1f2a44; border-color: #1f2a44; color: #fff; }
.app-modal-actions .danger { background: var(--red); border-color: var(--red); color: #fff; }

.transaction-list-card {
  width: min(980px, calc(100vw - 28px));
  max-height: min(720px, calc(100vh - 40px));
  overflow: hidden;
}

.transaction-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.transaction-list-head strong {
  color: var(--ink);
  font-size: 20px;
}

.transaction-list-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
}

.transaction-list-close .icon {
  width: 18px;
  height: 18px;
}

.transaction-list-search {
  width: 100%;
  margin-bottom: 12px;
}

.transaction-list-body {
  max-height: min(540px, calc(100vh - 190px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.transaction-list-table {
  width: 100%;
  border-collapse: collapse;
}

.transaction-list-table th,
.transaction-list-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.transaction-list-table th {
  position: sticky;
  top: 0;
  background: var(--soft-blue);
  color: var(--muted);
  font-size: 13px;
  z-index: 1;
}

.transaction-list-table td strong {
  display: block;
  color: var(--ink);
  font-size: 14px;
}

.transaction-list-table td span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.transaction-list-table tr:last-child td {
  border-bottom: 0;
}

.transaction-list-table button {
  min-height: 38px;
  min-width: 78px;
  font-weight: 700;
}

.transaction-list-table .primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.transaction-list-table .danger {
  border-color: var(--red);
  background: #fde2e2;
  color: #a71919;
}

.txn-list-amount {
  white-space: nowrap;
  font-weight: 700;
  color: var(--blue-dark);
}

.transaction-list-empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.preview-title { font-size: 21px; margin: 4px 0 12px; }
.status-pill.is-shared { background: var(--soft-blue); color: var(--blue-dark); }
:root[data-theme="dark"] .status-pill.is-shared { background: #1b3252; color: #6aa6ff; }

/* Settings password modal (reuses the popup overlay, blue accent). */
.pw-modal .compliance-popup-card {
  border-color: var(--blue);
  border-top-color: var(--blue);
}

.pw-modal .compliance-popup-card strong {
  color: var(--blue-dark);
}

.pw-note {
  margin: 8px 0 10px;
  color: var(--ink);
  font-size: 13px;
}

.pw-input {
  width: 100%;
  margin-bottom: 8px;
  text-transform: none;
}

.pw-error {
  margin: 0 0 8px;
  color: var(--red);
  font-size: 13px;
  font-weight: 600;
}

.pw-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.pw-buttons .pw-ok {
  border-color: var(--blue);
  background: var(--blue);
  color: white;
  font-weight: 700;
}

label {
  color: var(--muted);
  font-weight: 600;
  font-size: var(--fs-label);
}

input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-height: var(--ctrl-h);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--ink);
  font-size: var(--fs-base);
}

textarea { min-height: auto; }
input[type="checkbox"] { min-height: 0; }
input[type="radio"] { width: auto; min-height: 0; }

input[type="checkbox"]:not(.switch-input) {
  width: auto;
}

/* All typed input is shown in CAPS (the value is also upper-cased in JS so
   summaries, prints, shares and history are caps too). Selects are excluded so
   their option labels stay readable. */
input,
textarea {
  text-transform: uppercase;
}

/* Email IDs stay in small letters. */
input[type="email"] {
  text-transform: lowercase;
}

/* Free-text notes (welcome note, required documents, terms) keep normal case. */
.no-caps {
  text-transform: none;
}

textarea {
  resize: vertical;
}

/* ===== Printable quotation / invoice (renderPrintQuote) ===== */
.quote-print {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px;
  background: #fff;
  color: #1a2438;
  font-size: 13px;
  line-height: 1.5;
  text-transform: none;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.qp-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  border-bottom: 3px solid #173a7a;
  padding-bottom: 8px;
  margin-bottom: 11px;
}
.qp-head-text { min-width: 0; }
.qp-logo { max-height: 70px; max-width: 170px; object-fit: contain; flex: 0 0 auto; }
.qp-name { margin: 0; font-size: 22px; font-weight: 800; color: #173a7a; }
.qp-tagline { margin: 2px 0 0; font-size: 12px; font-style: italic; color: #5f6b80; }
.qp-addr { margin: 8px 0 0; color: #3a4660; }
.qp-contact { margin: 3px 0 0; color: #5f6b80; font-size: 12px; }

.qp-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 11px;
}
.qp-doctype {
  background: #173a7a;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .5px;
  padding: 7px 16px;
  border-radius: 4px;
}
.qp-ref { text-align: right; font-size: 12px; color: #3a4660; line-height: 1.6; }
.qp-ref span { color: #8893a7; }
.qp-ref strong { font-size: 15px; color: #173a7a; }

.qp-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 32px;
  margin-bottom: 11px;
  padding: 10px 14px;
  background: #f5f8fd;
  border: 1px solid #e1e9f4;
  border-radius: 6px;
}
.qp-info { margin: 0; }
.qp-info > div { display: flex; gap: 8px; padding: 2px 0; }
.qp-info dt { flex: 0 0 96px; color: #6b7689; font-weight: 600; }
.qp-info dd { margin: 0; font-weight: 600; color: #1a2438; word-break: break-word; }

.qp-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 11px;
}
.qp-table thead th {
  background: #173a7a;
  color: #fff;
  text-align: left;
  padding: 7px 10px;
  font-weight: 600;
}
.qp-table tbody td { padding: 6px 10px; border-bottom: 1px solid #e3e9f2; }
.qp-num { text-align: right; }

.qp-totals-wrap { display: flex; justify-content: flex-end; margin-bottom: 11px; }
.qp-totals { width: 340px; border-collapse: collapse; }
.qp-totals td { padding: 4px 12px; border-bottom: 1px solid #eef2f8; }
.qp-totals td:first-child { color: #3a4660; }
.qp-totals .qp-grand td {
  background: #142033;
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  border: none;
  padding: 8px 12px;
}
.qp-totals .qp-grand td:first-child { color: #fff; }

.qp-bank, .qp-note { margin-top: 9px; font-size: 11px; }
.qp-bank strong, .qp-note strong { display: block; margin-bottom: 2px; color: #173a7a; font-size: 11.5px; }
.qp-bank span, .qp-note p { margin: 0; color: #3a4660; line-height: 1.4; }

.qp-foot {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-top: 14px;
}
.qp-sign { text-align: center; min-width: 180px; }
.qp-sign-left { text-align: left; }
.qp-sign-for { font-weight: 600; color: #1a2438; }
.qp-sign-name { margin-top: 2px; color: #3a4660; font-size: 12px; }
.qp-sign-line { margin: 16px 0 4px; border-top: 1px solid #8893a7; }
.qp-sign-cap { font-size: 12px; color: #6b7689; }

/* ---- Print: force the whole quotation onto a single A4 page ---- */
@page { size: A4; margin: 0; }
.print-page {
  width: 210mm;
  height: 297mm;
  padding: 11mm 12mm;
  margin: 0 auto;
  background: #fff;
  box-sizing: border-box;
  overflow: hidden;
}
.print-page .quote-print {
  max-width: none;
  width: 100%;
  padding: 0;
  margin: 0;
  font-size: 12px;
  transform-origin: top left;
}

/* ---- Form A2 cum LRS Declaration: exactly TWO A4 pages ---- */
.a2-page {
  page-break-after: always;
  font-size: 12px;
  line-height: 1.45;
  color: #111;
  font-family: Arial, Helvetica, sans-serif;
}
.a2-page:last-child { page-break-after: auto; }
.a2-page p { margin: 7px 0; text-align: justify; }
.a2-title { text-align: center; font-size: 18px; font-weight: 800; letter-spacing: 1px; }
.a2-subtitle { text-align: center; font-weight: 700; margin-top: 3px; }
.a2-circular { text-align: center; font-size: 10px; color: #333; margin: 4px 0 10px; }
.a2-addr-row { display: flex; justify-content: space-between; align-items: flex-start; margin: 8px 0 4px; }
.a2-sec {
  font-weight: 700;
  background: #eef1f6;
  border: 1px solid #444;
  border-bottom: none;
  padding: 4px 8px;
  margin-top: 9px;
}
.a2-decl-head { text-align: center; border: 1px solid #444; margin-bottom: 8px; }
.a2-table { width: 100%; border-collapse: collapse; }
.a2-table td, .a2-table th { border: 1px solid #444; padding: 4px 8px; vertical-align: top; }
.a2-table .a2-label { width: 42%; font-weight: 600; background: #fafbfd; }
.a2-grid th { background: #eef1f6; text-align: left; }
.a2-grid td:first-child, .a2-grid th:first-child { width: 9%; text-align: center; }
.a2-center { text-align: center; }
.a2-sign-row { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 26px; gap: 24px; }
.a2-sign-box { border-top: 1px solid #444; padding-top: 4px; min-width: 230px; text-align: center; }
.a2-encls { font-size: 11px; color: #333; }
.a2-office { border: 1.5px solid #444; padding: 0 10px 10px; margin-top: 14px; }
.a2-office .a2-sec { margin: 10px -10px 8px; border: none; border-bottom: 1px solid #444; }
.a2-office-grid { display: flex; gap: 28px; margin-top: 8px; }

/* Settings logo preview */
.logo-preview-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; }
#settingLogoPreview { max-height: 48px; max-width: 120px; object-fit: contain; border: 1px solid var(--line, #cdd7e5); border-radius: 6px; padding: 3px; background: var(--panel); }

@media (max-width: 600px) {
  .qp-parties { grid-template-columns: 1fr; }
  .qp-title-row { flex-direction: column; align-items: flex-start; }
  .qp-ref { text-align: left; }
  .qp-totals { width: 100%; }
}

/* On-screen quotation preview — #quoteSummary holds the rendered qp-* document. */
#quoteSummary td,
#quoteSummary th {
  padding: 9px 12px;
  border: none;
  border-bottom: 1px solid var(--line);
  word-wrap: break-word;
}

/* Saved Quotations — card list (mobile-friendly). */
.history-count {
  margin: 6px 0 12px;
  color: var(--muted);
  font-weight: 700;
}

.history-search {
  width: 100%;
  margin: 4px 0 12px;
  padding: 9px 12px;
  text-transform: none;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
}

.field-hint.status-error {
  color: var(--red);
  font-weight: 700;
}

/* ---- Reports ---- */
.report-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}
.report-presets { display: flex; flex-wrap: wrap; gap: 8px; }
.report-preset {
  padding: 6px 12px;
  border: 1px solid var(--line, #cdd7e5);
  background: var(--panel);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
}
.report-preset.is-active { background: var(--brand, #173a7a); color: #fff; border-color: var(--brand, #173a7a); }
.report-dates { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.report-dates input[type="date"] { text-transform: none; }

.report-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.report-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line, #cdd7e5);
  border-radius: 10px;
  background: var(--tint);
}
.report-card-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.report-card-value { font-size: 19px; font-weight: 800; color: var(--ink, #141e33); overflow-wrap: anywhere; }

.report-subhead { margin: 18px 0 8px; font-size: 16px; }
.report-hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.report-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.report-table th, .report-table td { border-bottom: 1px solid var(--line, #e3e9f2); padding: 8px; text-align: left; }
.report-table th { background: var(--soft-blue); color: var(--blue-dark); }
.report-num { text-align: right; }
.report-table tr.report-warn td { background: #fdf1d8; }
:root[data-theme="dark"] .report-table tr.report-warn td { background: #3a2f12; }

/* App Theme picker (Settings) — list rows with a radio on the right. */
.theme-options { display: flex; flex-direction: column; margin: 2px 0 8px; }
.theme-option {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 4px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.theme-option:last-child { border-bottom: none; }
.theme-option-text { font-size: 15px; font-weight: 500; color: var(--ink); }
.theme-option input[type="radio"] { width: 20px; height: 20px; accent-color: var(--blue); }

/* Toggle switch (App Lock, Cloud Database Sync). */
.switch-input {
  appearance: none; -webkit-appearance: none;
  width: 44px; height: 24px; min-height: 0; flex: 0 0 auto;
  display: inline-block; vertical-align: middle;
  border-radius: 999px; background: var(--line); position: relative; cursor: pointer;
  transition: background .2s; border: none; padding: 0;
  /* Inner ring keeps the OFF state visible on white cells (and in dark mode). */
  box-shadow: inset 0 0 0 1px var(--muted);
}
.switch-input::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch-input:checked { background: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.switch-input:checked::after { transform: translateX(20px); }

/* App-launch lock screen. */
.lock-screen {
  position: fixed; inset: 0; z-index: 100000;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(135deg, #0d3f82, #1459b8);
}
.lock-card {
  width: 100%; max-width: 360px; padding: 28px 22px; text-align: center;
  background: var(--panel); color: var(--ink); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.lock-icon {
  width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--soft-blue); color: var(--blue-dark);
}
.lock-icon .icon { width: 28px; height: 28px; }
.lock-card h2 { margin: 0 0 4px; font-size: 20px; }
.lock-card p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.lock-input { text-align: center; text-transform: none; margin-bottom: 10px; }
.lock-error { color: var(--red); font-size: 13px; margin: 0 0 10px; }
.lock-unlock {
  width: 100%; min-height: 46px; border: none; border-radius: 10px;
  background: var(--blue); color: #fff; font-weight: 700; font-size: 15px; cursor: pointer;
}

/* First-run, white-label business setup */
.setup-screen {
  position: fixed; inset: 0; z-index: 100000;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 20px; overflow-y: auto;
  background: linear-gradient(135deg, #0d3f82, #1459b8);
}
.setup-card {
  width: 100%; max-width: 560px; margin: auto;
  padding: 22px 20px 20px;
  background: var(--panel); color: var(--ink); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.setup-head { text-align: center; margin-bottom: 14px; }
.setup-icon {
  width: 52px; height: 52px; margin: 0 auto 10px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  background: var(--soft-blue); color: var(--blue-dark);
}
.setup-icon .icon { width: 26px; height: 26px; }
.setup-head h2 { margin: 0 0 4px; font-size: 20px; }
.setup-head p { margin: 0; color: var(--muted); font-size: 13px; }
.setup-cloud {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--soft-blue);
}
.setup-cloud strong { display: block; color: var(--blue-dark); margin-bottom: 4px; }
.setup-cloud p { margin: 0 0 10px; color: var(--muted); font-size: 12px; }
.setup-cloud .setup-grid { margin: 0; }
.setup-cloud-pull {
  width: 100%; min-height: 40px; margin-top: 10px; border-radius: 10px;
  border: 1px solid var(--blue); background: var(--blue); color: #fff;
  font-weight: 700; cursor: pointer;
}
.setup-cloud-status { display: block; margin-top: 8px; }
.setup-grid input, .setup-grid textarea {
  height: 40px; min-height: 40px; font-size: 14px; padding: 7px 10px; border-radius: 10px;
}
.setup-grid textarea { height: auto; }
.setup-grid .req { color: var(--red); }
.setup-error { color: var(--red); font-size: 13px; margin: 10px 0 0; text-align: center; }

/* Multi-tenant login + company gate */
.auth-toggle { text-align: center; margin-top: 12px; }
.auth-toggle a { color: var(--blue); cursor: pointer; text-decoration: none; }
.company-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.company-pick {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); color: var(--ink); font-weight: 600; font-size: 15px; cursor: pointer;
}
.company-role { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.company-or { text-align: center; margin: 10px 0; }
/* Team (Phase 5) */
.team-modal .app-modal-card { max-width: 460px; width: 100%; }
.team-body { margin: 6px 0 10px; max-height: 46vh; overflow-y: auto; }
.team-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.team-row:last-child { border-bottom: none; }
.team-email { flex: 1; font-size: 14px; word-break: break-all; }
.team-row .company-role { flex: 0 0 auto; }
.team-remove { flex: 0 0 auto; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 5px 7px; cursor: pointer; color: var(--red); }
.team-remove[disabled] { opacity: 0.4; cursor: not-allowed; }
.team-remove .icon { width: 15px; height: 15px; }
.team-add { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.team-add #teamAddEmail { flex: 1; min-width: 160px; }
.team-add .team-add-btn { background: var(--blue); border: 1px solid var(--blue); color: #fff; border-radius: 8px; padding: 8px 14px; font-weight: 600; cursor: pointer; }
.team-error { margin-top: 8px; }
/* Super-admin dashboard */
.admin-dashboard { position: fixed; inset: 0; z-index: 1000; overflow-y: auto; background: var(--bg); color: var(--ink); }
.admin-bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.admin-bar-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; }
.admin-bar-brand .icon { width: 22px; height: 22px; color: var(--blue); }
.admin-bar-user { display: flex; align-items: center; gap: 14px; }
.admin-bar-email { font-size: 13px; color: var(--muted); }
.admin-bar-user .gate-signout { color: var(--blue); font-weight: 600; cursor: pointer; white-space: nowrap; }
.admin-content { max-width: 980px; margin: 0 auto; padding: 20px 22px 64px; }
.admin-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 0 0 18px; }
.admin-stat { text-align: center; padding: 16px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); font-size: 12.5px; color: var(--muted); }
.admin-stat b { display: block; font-size: 26px; color: var(--ink); line-height: 1.1; margin-bottom: 2px; }
.admin-stats-empty { grid-column: 1 / -1; margin: 0; padding: 14px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }
.admin-panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; margin-bottom: 16px; }
.admin-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.admin-panel-head h3 { margin: 0; font-size: 16px; }
.admin-panel-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-panel-actions button { padding: 8px 14px; border: 1px solid var(--line); background: var(--bg); border-radius: 9px; font-weight: 600; font-size: 13px; cursor: pointer; color: var(--ink); }
.admin-list { display: flex; flex-direction: column; gap: 10px; }
.admin-row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.admin-name { font-weight: 600; font-size: 15px; }
.admin-meta { grid-column: 1 / 2; font-size: 12px; color: var(--muted); }
.admin-row-actions { grid-row: 1 / 3; display: flex; gap: 6px; }
.admin-row-actions button { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; color: var(--ink); white-space: nowrap; }
.admin-create .setup-save { width: auto; min-width: 190px; margin-top: 4px; }
.admin-form-legend { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 12px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.admin-form-legend:first-child { margin-top: 0; }
.admin-code { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; color: var(--muted); }
.admin-status-badge { font-size: 11px; font-weight: 700; background: rgba(239,68,68,0.14); color: var(--red); border-radius: 6px; padding: 1px 7px; }
.admin-row.is-inactive { opacity: 0.62; }
.admin-row.is-inactive .admin-status { color: var(--green); }
.admin-settings-sec { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.admin-settings-sec > strong { display: block; margin-bottom: 6px; }
.admin-sa-body { margin-bottom: 8px; }
.user-actions { display: flex; gap: 6px; align-items: center; flex: 0 0 auto; }
.user-reset { flex: 0 0 auto; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 12px; font-size: 13px; cursor: pointer; color: var(--blue); }
.user-reset[disabled] { color: var(--green); cursor: default; }
.user-delete { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 6px 8px; cursor: pointer; color: var(--red); }
.user-delete[disabled] { opacity: 0.4; cursor: not-allowed; }
.user-delete .icon { width: 15px; height: 15px; }
#userSearch { width: 100%; margin-bottom: 8px; }
@media (max-width: 640px) {
  .admin-stats { grid-template-columns: repeat(2, 1fr); }
  .admin-content { padding: 16px 14px 48px; }
  .admin-bar { padding: 11px 14px; }
  .admin-bar-email { display: none; }
}
/* Admin create-user: temp-password row + success notes */
.admin-pw-row { display: flex; gap: 8px; }
.admin-pw-row input { flex: 1; }
.admin-pw-row button { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 12px; cursor: pointer; color: var(--ink); white-space: nowrap; }
.admin-created-info, .newuser-info { margin-top: 10px; font-size: 13px; padding: 9px 11px; border-radius: 9px; background: rgba(16,185,129,0.12); border: 1px solid var(--green); }
.team-modal .admin-settings-sec input { width: 100%; margin-bottom: 6px; }
.team-modal .admin-settings-sec .admin-pw-row input { margin-bottom: 0; }
/* Boot splash (multi-tenant) — covers the app until the login/admin gate resolves */
.mt-boot-splash { display: flex; align-items: center; justify-content: center; }
.boot-spinner { width: 44px; height: 44px; border: 4px solid rgba(255,255,255,0.3); border-top-color: #fff; border-radius: 50%; animation: boot-spin 0.8s linear infinite; }
@keyframes boot-spin { to { transform: rotate(360deg); } }
/* Header Log out button (multi-tenant) */
#headerLogout { margin-left: 12px; padding: 5px 13px; border: 1px solid currentColor; background: transparent; color: inherit; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; opacity: 0.85; white-space: nowrap; }
#headerLogout:hover { opacity: 1; background: rgba(127,127,127,0.18); }
/* Migrations panel */
.migrations-body, .migrations-edge { font-size: 14px; margin-top: 6px; }
.migrations-row { padding: 6px 2px; border-bottom: 1px solid var(--line); }
.migrations-row.ok { color: var(--ink); }
.migrations-row.bad { color: var(--red); font-weight: 600; }
.migrations-row.optional { color: var(--muted); font-size: 13px; line-height: 1.4; }
.migrations-edge .migrations-row { border-bottom: none; }
.migrations-summary { margin-top: 10px; padding: 9px 11px; border-radius: 9px; font-size: 13px; }
.migrations-summary.ok { background: rgba(16,185,129,0.12); border: 1px solid var(--green); }
.migrations-summary.bad { background: rgba(239,68,68,0.12); border: 1px solid var(--red); }
.migrations-run { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.migrations-run > strong { display: block; margin-bottom: 4px; }
.migrations-run .team-add { margin-top: 8px; }
.migrations-run .mig-token { flex: 1; }
.mig-adv { margin-top: 8px; font-size: 13px; }
.mig-adv summary { cursor: pointer; color: var(--blue); }
.mig-adv textarea { width: 100%; margin-top: 6px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; box-sizing: border-box; }
.mig-result { margin-top: 10px; padding: 9px 11px; border-radius: 9px; font-size: 13px; line-height: 1.4; word-break: break-word; }
.mig-result.ok { background: rgba(16,185,129,0.12); border: 1px solid var(--green); }
.mig-result.bad { background: rgba(239,68,68,0.12); border: 1px solid var(--red); color: var(--red); }
/* Always-visible version badge (every screen: login, gate, console, app). */
.version-badge {
  position: fixed; bottom: 6px; right: 10px; z-index: 99999;
  font-size: 11px; line-height: 1; color: var(--muted, #6b7280);
  background: rgba(255,255,255,0.72); border: 1px solid var(--line, #e5e7eb);
  border-radius: 999px; padding: 3px 8px; opacity: 0.85;
  pointer-events: none; user-select: none;
}
/* Auth: referral + forgot password */
.auth-forgot { text-align: right; margin: -2px 0 6px; }
.auth-forgot-link, .auth-switch { color: var(--blue); cursor: pointer; }
.auth-referral-field input { letter-spacing: 0.06em; text-transform: uppercase; }
/* Invite codes */
.invite-new { margin: 4px 0 8px; font-size: 14px; }
.invite-new code, .team-email code { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 700; letter-spacing: 0.05em; background: var(--bg); padding: 2px 6px; border-radius: 6px; }
.invite-section { margin: 10px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.team-row.used { opacity: 0.7; }
.setup-save {
  width: 100%; min-height: 46px; margin-top: 14px; border: none; border-radius: 10px;
  background: var(--blue); color: #fff; font-weight: 700; font-size: 15px; cursor: pointer;
}

/* Dark-mode tweaks for the invoice status pill. */
:root[data-theme="dark"] .status-pill.is-invoice,
:root[data-theme="dark"] .hist-card .status-pill.is-invoice { background: #173a2c; color: #58d39a; }

/* Report menu: icon-grid that reveals one detailed table at a time. */
.report-menu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 16px 0 6px;
}
.report-menu-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.report-menu-card .icon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
}
.report-menu-card .icon-badge .icon { width: 22px; height: 22px; }
.report-menu-card.is-active {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(20, 89, 184, 0.18);
  background: var(--soft-blue);
}

/* Back-to-Home button at the top of each main page. */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0 6px;
  padding: 6px 10px 6px 6px;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--blue-dark);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}
.back-btn .icon { width: 16px; height: 16px; }
.back-btn:hover { background: var(--soft-blue); border-color: var(--blue); }

/* ---- Home dashboard ---- */
.page-header-main { cursor: pointer; }

.home-greeting { margin: 4px 0 16px; }
.home-company { margin: 0; font-size: 22px; color: var(--ink); }
.home-date { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.home-kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 22px; }
.kpi-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 16px; border-radius: 16px;
  background: linear-gradient(150deg, #1f2a44, #33425f);
  color: #fff; box-shadow: var(--shadow);
}
.kpi-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 10px; background: rgba(255, 255, 255, 0.14);
}
.kpi-icon .icon { width: 19px; height: 19px; }
.kpi-value { font-size: 22px; font-weight: 800; line-height: 1.1; overflow-wrap: anywhere; }
.kpi-label { font-size: 12px; color: #c7d2e4; }

.home-menu-title { font-size: 16px; margin: 0 0 10px; }
.home-menu { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.home-card {
  display: flex; flex-direction: row; align-items: center; gap: 12px; text-align: left;
  padding: 12px 16px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel); color: var(--ink); font-size: 15px; font-weight: 600; cursor: pointer;
}
.home-badge {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  width: 40px; height: 40px; border-radius: 12px; background: var(--blue); color: #fff;
}
.home-badge .icon { width: 20px; height: 20px; }

/* Filter chips (History). */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}
.chip {
  padding: 7px 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  font-size: 14px;
  cursor: pointer;
  color: var(--ink);
}
.chip.is-active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Redesigned History card — compact, key info first, 3 actions + More menu. */
.hist-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 4px 14px rgba(22, 38, 70, 0.06);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.hist-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.hist-ref { font-size: 16px; font-weight: 800; color: var(--blue-dark); }
.hist-card .status-pill {
  font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px;
  background: var(--soft-gold); color: var(--gold);
}
.hist-card .status-pill.is-invoice { background: #e3f4ec; color: var(--green); }
.hist-cust { font-size: 16px; font-weight: 700; }
.hist-txn { font-size: 14px; color: var(--muted); margin-top: 1px; }
.hist-forex { font-size: 14px; color: var(--ink); margin-top: 4px; }
.hist-total { font-size: 15px; margin-top: 4px; }
.hist-total strong { font-size: 19px; color: var(--ink); }
.hist-valid { font-size: 13px; color: var(--muted); margin-top: 2px; }
.hist-actions { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.hist-act {
  flex: 1 1 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 6px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  font-weight: 600; font-size: 14px; cursor: pointer;
}
.hist-act .icon { width: 17px; height: 17px; }
.hist-more { position: relative; flex: 0 0 auto; }
.hist-more > summary {
  list-style: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
}
.hist-more > summary::-webkit-details-marker { display: none; }
.hist-more[open] > summary { background: var(--soft-blue); border-color: var(--blue); }
.hist-more-menu {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 30;
  min-width: 168px; padding: 6px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 12px 30px rgba(22, 38, 70, 0.18);
}
.hist-more-menu button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 10px; border: none; background: transparent; border-radius: 8px;
  font-size: 15px; text-align: left; cursor: pointer; color: var(--ink);
}
.hist-more-menu button:hover { background: var(--soft-blue); }
.hist-more-menu button.danger { color: var(--red); }
.hist-more-menu .icon { width: 18px; height: 18px; }

/* ---- Toast ---- */
.toast-host {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 9999;
}
.toast {
  background: #1f2a44;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity .25s ease, transform .25s ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

.history-list {
  display: grid;
  gap: 12px;
}

.status-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--soft-gold);
  color: #805300;
  font-size: 12px;
  font-weight: 700;
}

.status-pill.is-invoice {
  background: #e3f6ec;
  color: var(--green);
}

/* Working-screen footer: a single small muted line pinned at the very bottom,
   below the action bar. The full company / bank / GST block appears in the
   Preview / Print / PDF, not here. */
.app-footer {
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 7px 12px;
  text-align: center;
  background: var(--panel);
  border-top: 1px solid var(--line);
}

.footer-credit {
  margin: 0;
  font-size: 11px;
  line-height: 1.3;
  color: var(--muted);
}

@media (max-width: 820px) {
  /* Keep [hidden] rows/elements hidden — the stacking rules below set
     display:block, which would otherwise override the hidden attribute. */
  [hidden] {
    display: none !important;
  }

  /* Compact, readable controls on mobile. */
  input,
  select,
  textarea {
    font-size: var(--fs-base);
  }

  /* Input form tables (Customer / Transaction / LRS / Charges / Settings):
     stack so each label sits on its own line above a full-width control. */
  form fieldset table,
  form fieldset table tbody,
  form fieldset table tr,
  form fieldset table td {
    display: block;
    width: 100% !important;
  }

  form fieldset table thead {
    display: none;
  }

  form fieldset table td {
    padding: 4px 0;
  }

  /* On-screen quotation preview: compact the cells on small screens. */
  #quoteSummary td,
  #quoteSummary th {
    padding: 7px 8px;
  }

  .bottom-actions {
    gap: 6px;
    padding: 7px 8px;
  }

  .action-strip {
    justify-content: stretch;
  }

  .action-group {
    flex: 1 1 0;
    gap: 5px;
  }

  .bottom-actions button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 38px;
    padding: 7px 4px;
    font-size: 13px;
  }

  .bottom-actions .icon {
    width: 15px;
    height: 15px;
  }

  .bottom-actions button span {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Cart card: the two headline numbers, tap to open the full Summary. */
  .cart-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    min-height: 52px;
    margin-bottom: 8px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--soft-blue);
    text-align: left;
  }

  .cart-item {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
  }

  .cart-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
  }

  .cart-item strong {
    font-size: 17px;
    font-weight: 800;
    color: var(--ink);
  }

  .cart-caret {
    margin-left: auto;
    color: var(--blue-dark);
    font-size: 14px;
  }

  /* Compact spacing on phones. */
  fieldset {
    margin: 6px 0;
    padding: 10px 12px;
  }

  legend {
    padding: 5px 11px;
    font-size: 15px;
  }

  label {
    font-size: 13px;
  }

  input,
  select,
  textarea {
    padding: 8px 12px;
    min-height: var(--ctrl-h);
  }

  form fieldset table td {
    padding: 2px 0;
  }

  .settings-currency-table {
    display: table !important;
    table-layout: fixed;
  }

  .settings-currency-table thead {
    display: table-header-group !important;
  }

  .settings-currency-table tbody {
    display: table-row-group !important;
  }

  .settings-currency-table tr {
    display: table-row !important;
  }

  .settings-currency-table th,
  .settings-currency-table td {
    display: table-cell !important;
    padding: 4px 5px;
  }

  .settings-currency-table th:nth-child(1),
  .settings-currency-table td:nth-child(1) {
    width: 72px !important;
  }

  .settings-currency-table th:nth-child(3),
  .settings-currency-table td:nth-child(3) {
    width: 74px !important;
  }

  .settings-currency-table input {
    height: 30px;
    min-height: 30px;
    padding: 4px 7px;
    font-size: 13px;
  }

  .settings-currency-table .removeSettingCurrency {
    min-height: 30px;
    padding: 4px 6px;
    font-size: 12px;
  }

  .pages {
    padding-top: 6px;
  }

  .quote-title {
    margin: 6px 0 8px;
    font-size: 20px;
  }

  /* Reserve space for the nav (gesture/3-button) bar so the scroll area ends
     above it — even when env() reports 0. */
  body {
    padding-bottom: max(48px, env(safe-area-inset-bottom, 0px));
  }

  .page-header {
    display: block;
    /* Clear the status bar even when env() reports 0. */
    padding: max(44px, calc(env(safe-area-inset-top, 0px) + 8px)) 16px 10px;
  }

  .page-header h1 {
    font-size: 20px;
  }

  /* Tagline + email are dropped on phones to keep the header compact
     (email still appears in Settings and on the Preview / Print / PDF). */
  #headerTagline,
  #headerEmail {
    display: none;
  }

  .header-details {
    justify-content: flex-start;
    margin-top: 6px;
    gap: 6px;
  }

  .header-details span:not(:empty) {
    padding: 4px 9px;
    font-size: 12px;
  }

  .header-details .icon { width: 13px; height: 13px; }
}

@media print {
  /* Undo the app-shell so the whole printout flows across pages. */
  html,
  body {
    height: auto;
    display: block;
    overflow: visible;
    background: #fff;
    margin: 0;
    padding: 0;
  }

  /* A box that is EXACTLY 297mm tall overflows the page by sub-pixel rounding
     and spills a blank trailing page. When actually printing, size each page
     to its content instead — the memo/quote is pre-scaled to fit and Form A2
     is designed to fit, so nothing exceeds one page. */
  .print-page {
    height: auto;
    min-height: 0;
    overflow: visible;
  }
  .a2-page { page-break-after: always; }
  .a2-page:last-child { page-break-after: auto; }

  .scroll-area {
    overflow: visible;
  }

  .page-header,
  .quote-title,
  form,
  #quoteSummary,
  #quoteHistory {
    width: auto;
  }
}
