/* Cleenzy public-facing styles — booking form + client invoice page.
 * Brand colors approximate cleenzy.ca (deep blue hero, teal accent).
 *
 * v1.2: two robustness layers were added at the bottom of this file:
 *   1. VISIBILITY GUARD — every text/field/button colour is set explicitly
 *      (with ID-level specificity), so a theme or Elementor kit can never
 *      turn our text white / transparent any more.
 *   2. PRINT ISOLATION — printing or "Save as PDF" outputs the invoice
 *      only (no theme header/footer, chat bubble, WhatsApp button).
 */
:root {
  --cz-ink: #142433;
  --cz-blue: #1C3D6B;
  --cz-teal: #1F8A70;
  --cz-line: #e2e6ec;
  --cz-bg: #ffffff;
  --cz-muted: #6b7686;
  --cz-danger: #c1503a;
  --cz-amber-soft: #fbf1dd;
}

.cleenzy-form-wrap, .cleenzy-invoice-wrap {
  max-width: 640px;
  margin: 0 auto;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--cz-ink);
  color-scheme: light;
}

.cleenzy-success {
  background: #e8f6f1;
  border: 1px solid var(--cz-teal);
  color: var(--cz-teal);
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  font-weight: 600;
}

.cleenzy-row { display: flex; gap: 14px; }
.cleenzy-row .cleenzy-field { flex: 1; }
.cleenzy-field { margin-bottom: 14px; }
.cleenzy-field label { display: block; font-size: 0.82rem; font-weight: 600; margin-bottom: 5px; color: var(--cz-blue); }
.cleenzy-field input, .cleenzy-field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--cz-line); border-radius: 8px;
  font-size: 0.95rem; font-family: inherit;
}

.cleenzy-btn {
  display: inline-block; padding: 12px 22px; border-radius: 9px; border: none;
  font-weight: 700; font-size: 0.95rem; cursor: pointer; width: 100%;
}
.cleenzy-btn-primary { background: var(--cz-blue); color: #fff; }
.cleenzy-btn-primary:hover { background: var(--cz-teal); }
.cleenzy-btn-ghost { background: transparent; border: 1px solid var(--cz-line); color: var(--cz-ink); margin-top: 14px; }

/* Invoice */
.cleenzy-inv-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  border-bottom: 2px solid var(--cz-ink); padding-bottom: 16px; margin-bottom: 16px;
}
.cleenzy-brand { display: flex; gap: 12px; align-items: center; }
/* Fixed-size box + !important: many themes/page builders (Elementor
 * included) ship "img { height:auto !important; max-width:100% }" which
 * would otherwise blow this logo up to the full column width. */
.cleenzy-logo-box {
  display: inline-flex !important; align-items: center; justify-content: flex-start;
  width: 130px !important; height: 46px !important; overflow: hidden; flex-shrink: 0;
}
.cleenzy-logo-img {
  height: 46px !important; width: auto !important; max-width: 130px !important;
  max-height: 46px !important; object-fit: contain !important;
}
.cleenzy-logo-fallback {
  height: 44px; width: 44px; border-radius: 10px; background: var(--cz-teal);
  color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800;
}
.cleenzy-company-name { font-weight: 800; font-size: 1.05rem; color: var(--cz-blue); }
.cleenzy-company-contact { color: var(--cz-muted); font-size: 0.8rem; }
.cleenzy-inv-meta { text-align: right; font-size: 0.8rem; color: var(--cz-muted); }
.cleenzy-inv-meta strong { display: block; font-size: 1rem; color: var(--cz-ink); }

.cleenzy-bill-to {
  display: flex; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--cz-line);
  margin-bottom: 12px; font-size: 0.9rem;
}
.cleenzy-label { font-size: 0.7rem; color: var(--cz-muted); margin-bottom: 3px; }
.cleenzy-name { font-weight: 700; }
.cleenzy-muted { color: var(--cz-muted); }
.cleenzy-status { font-weight: 700; }
.cleenzy-status-paid { color: var(--cz-teal); }
.cleenzy-status-partially_paid { color: #b8860b; }
.cleenzy-status-new, .cleenzy-status-invoice_sent { color: var(--cz-danger); }

table.cleenzy-lines { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin-bottom: 10px; }
table.cleenzy-lines th { text-align: left; font-size: 0.72rem; color: var(--cz-muted); border-bottom: 1px solid var(--cz-line); padding-bottom: 6px; }
table.cleenzy-lines th:last-child, table.cleenzy-lines td:last-child { text-align: right; }
table.cleenzy-lines td { padding: 8px 0; border-bottom: 1px solid var(--cz-line); }
.cleenzy-item-detail-line { color: var(--cz-muted); font-size: 0.8rem; margin-top: 3px; font-weight: 400; }

.cleenzy-totals { margin-bottom: 18px; }
.cleenzy-tline { display: flex; justify-content: space-between; padding: 5px 0; color: var(--cz-muted); font-size: 0.88rem; }
.cleenzy-tline.cleenzy-balance { color: var(--cz-danger); font-weight: 700; }
.cleenzy-grand {
  display: flex; justify-content: space-between; padding: 12px 14px; background: var(--cz-amber-soft);
  border-radius: 9px; font-weight: 800; font-size: 1.1rem; margin-top: 6px;
}

.cleenzy-pay-box { border: 1px solid var(--cz-line); border-radius: 12px; padding: 18px; margin-top: 10px; }
.cleenzy-demo-flag {
  background: #fff4e5; color: #a5620d; font-size: 0.78rem; font-weight: 700;
  padding: 6px 10px; border-radius: 6px; display: inline-block; margin-bottom: 14px;
}
.cleenzy-pay-instructions {
  display: block; background: #eef4fb; color: #1c3d6b; font-weight: 400;
  padding: 14px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 0.88rem; line-height: 1.5;
}
.cleenzy-pay-instructions strong { display: block; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 4px; }
.cleenzy-pay-account { font-size: 1.15rem; font-weight: 800; display: inline-block; margin-bottom: 4px; }
.cleenzy-pay-instructions-text { color: #45618f; font-size: 0.82rem; margin-top: 4px; }

.cleenzy-pay-toggle { display: flex; gap: 8px; margin-bottom: 14px; }
.cleenzy-pay-toggle button {
  flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--cz-line);
  background: transparent; font-weight: 600; cursor: pointer;
}
.cleenzy-pay-toggle button.active { background: var(--cz-blue); color: #fff; border-color: var(--cz-blue); }

.cleenzy-partial-row { margin-bottom: 16px; }
.cleenzy-remaining-preview { font-size: 0.82rem; color: var(--cz-muted); margin-top: 6px; }

.cleenzy-pay-response { font-size: 0.85rem; margin-top: 10px; color: var(--cz-danger); }
.cleenzy-pay-response.cleenzy-pay-ok { color: var(--cz-teal); }

.cleenzy-paid-flag {
  text-align: center; background: #e8f6f1; color: var(--cz-teal); font-weight: 700;
  padding: 14px; border-radius: 10px;
}

@media (max-width: 560px) {
  .cleenzy-row { flex-direction: column; gap: 0; }
}


/* ==========================================================================
 * 1. VISIBILITY GUARD
 * --------------------------------------------------------------------------
 * Root cause of the "white / invisible text" bug: inputs, labels and
 * buttons had no explicit colour, so they inherited whatever the active
 * theme / Elementor kit sets (often white). Everything below pins colours
 * explicitly. `:is(#cleenzy-invoice-root, .cleenzy-form-wrap)` gives ID-level
 * specificity, so theme rules cannot win (and it covers the booking form too).
 * ========================================================================== */

/* The invoice always sits on its own white sheet, so dark ink is readable
 * even if the page section behind it is dark. */
#cleenzy-invoice-root {
  max-width: 680px;
  padding: 20px;
  box-sizing: border-box;
  background: #fff !important;
  color: var(--cz-ink) !important;
  border-radius: 14px;
  line-height: 1.45;
  text-align: left;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
#cleenzy-invoice-root *,
.cleenzy-form-wrap * { box-sizing: border-box; }

/* Plain text: inherit the ink colour, ignore theme colour/opacity tricks. */
#cleenzy-invoice-root :is(div, span, strong, b, p, td, th, label, small) {
  color: inherit !important;
  opacity: 1 !important;
  text-shadow: none !important;
}

/* Muted / secondary text */
#cleenzy-invoice-root :is(.cleenzy-company-contact, .cleenzy-inv-meta, .cleenzy-inv-meta span,
  .cleenzy-label, .cleenzy-muted, .cleenzy-item-detail-line, .cleenzy-tline,
  .cleenzy-tline span, .cleenzy-remaining-preview) { color: var(--cz-muted) !important; }
#cleenzy-invoice-root .cleenzy-inv-meta strong,
#cleenzy-invoice-root .cleenzy-name,
#cleenzy-invoice-root .cleenzy-remaining-preview strong { color: var(--cz-ink) !important; }
#cleenzy-invoice-root .cleenzy-company-name { color: var(--cz-blue) !important; }
#cleenzy-invoice-root .cleenzy-logo-fallback { color: #fff !important; background: var(--cz-teal) !important; }

/* Status colours */
#cleenzy-invoice-root .cleenzy-status-paid { color: var(--cz-teal) !important; }
#cleenzy-invoice-root .cleenzy-status-partially_paid { color: #b8860b !important; }
#cleenzy-invoice-root :is(.cleenzy-status-new, .cleenzy-status-invoice_sent) { color: var(--cz-danger) !important; }
#cleenzy-invoice-root .cleenzy-tline.cleenzy-balance,
#cleenzy-invoice-root .cleenzy-tline.cleenzy-balance span { color: var(--cz-danger) !important; }

/* Grand total keeps its soft amber box + dark text */
#cleenzy-invoice-root .cleenzy-grand,
#cleenzy-invoice-root .cleenzy-grand span {
  color: var(--cz-ink) !important;
}
#cleenzy-invoice-root .cleenzy-grand { background: var(--cz-amber-soft) !important; }

/* Notices */
#cleenzy-invoice-root .cleenzy-demo-flag { color: #a5620d !important; background: #fff4e5 !important; }
#cleenzy-invoice-root .cleenzy-pay-instructions { color: #1c3d6b !important; background: #eef4fb !important; }
#cleenzy-invoice-root .cleenzy-pay-instructions-text { color: #45618f !important; }
#cleenzy-invoice-root .cleenzy-pay-response { color: var(--cz-danger) !important; }
#cleenzy-invoice-root .cleenzy-pay-response.cleenzy-pay-ok { color: var(--cz-teal) !important; }
#cleenzy-invoice-root .cleenzy-paid-flag { color: var(--cz-teal) !important; background: #e8f6f1 !important; }
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) .cleenzy-success { color: var(--cz-teal) !important; background: #e8f6f1 !important; }

/* Line-items table: theme "table td { border:1px solid }" / zebra rows /
 * white header text are neutralised. Clean horizontal rules only. */
#cleenzy-invoice-root table.cleenzy-lines {
  width: 100%;
  margin: 0 0 10px;
  border: 0 !important;
  border-collapse: collapse !important;
  background: transparent !important;
}
#cleenzy-invoice-root table.cleenzy-lines :is(thead, tbody, tr) { background: transparent !important; border: 0 !important; }
#cleenzy-invoice-root table.cleenzy-lines :is(th, td) {
  background: transparent !important;
  border: 0 !important;
  border-bottom: 1px solid var(--cz-line) !important;
  padding: 8px 0;
  vertical-align: top;
  text-transform: none;
  letter-spacing: normal;
  color: var(--cz-ink) !important;
}
#cleenzy-invoice-root table.cleenzy-lines th {
  color: var(--cz-muted) !important;
  font-size: 0.72rem;
  font-weight: 600;
  text-align: left;
  padding: 0 0 6px;
}
#cleenzy-invoice-root table.cleenzy-lines :is(th, td):nth-child(2) { text-align: center; width: 64px; }
#cleenzy-invoice-root table.cleenzy-lines :is(th, td):last-child { text-align: right; }
#cleenzy-invoice-root table.cleenzy-lines .cleenzy-item-detail-line { color: var(--cz-muted) !important; }

/* Form labels */
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) :is(.cleenzy-field label, .cleenzy-partial-row label) {
  display: block;
  margin: 0 0 5px;
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: none;
  letter-spacing: normal;
  color: var(--cz-blue) !important;
}

/* Inputs / selects (this now also styles the "Amount to pay now" field,
 * which previously had no styling at all and typed in white). */
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) :is(.cleenzy-field input, .cleenzy-field select, .cleenzy-partial-row input) {
  display: block;
  width: 100%;
  height: auto;
  padding: 10px 12px;
  background: #fff !important;
  color: var(--cz-ink) !important;
  -webkit-text-fill-color: var(--cz-ink);
  border: 1px solid var(--cz-line) !important;
  border-radius: 8px;
  box-shadow: none;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  opacity: 1;
}
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) :is(.cleenzy-field input, .cleenzy-field select, .cleenzy-partial-row input):focus {
  border-color: var(--cz-blue) !important;
  outline: none;
  box-shadow: 0 0 0 3px rgba(28, 61, 107, 0.15);
}
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) :is(.cleenzy-field input, .cleenzy-partial-row input)::placeholder {
  color: #8a94a3 !important;
  -webkit-text-fill-color: #8a94a3;
  opacity: 1;
}
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) :is(.cleenzy-field input, .cleenzy-partial-row input):-webkit-autofill {
  -webkit-text-fill-color: var(--cz-ink);
  box-shadow: 0 0 0 1000px #fff inset;
}
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) .cleenzy-field select option { color: var(--cz-ink); background: #fff; }

/* Buttons: colour AND background pinned for every state, so a theme's
 * "button:hover { color:#fff }" can't create white-on-white. */
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) :is(.cleenzy-btn, .cleenzy-pay-toggle button) {
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.3;
  text-transform: none;
  letter-spacing: normal;
  text-shadow: none;
  box-shadow: none;
  opacity: 1;
}
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) .cleenzy-btn-primary,
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) .cleenzy-btn-primary:focus {
  background: var(--cz-blue) !important;
  color: #fff !important;
  -webkit-text-fill-color: #fff;
  border: 0 !important;
}
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) .cleenzy-btn-primary:hover {
  background: var(--cz-teal) !important;
  color: #fff !important;
  -webkit-text-fill-color: #fff;
}
:is(#cleenzy-invoice-root, .cleenzy-form-wrap) .cleenzy-btn-primary:disabled { opacity: 0.7; cursor: wait; }

#cleenzy-invoice-root .cleenzy-btn-ghost,
#cleenzy-invoice-root .cleenzy-btn-ghost:focus {
  background: #fff !important;
  color: var(--cz-ink) !important;
  -webkit-text-fill-color: var(--cz-ink);
  border: 1px solid var(--cz-line) !important;
}
#cleenzy-invoice-root .cleenzy-btn-ghost:hover {
  background: #f3f6fa !important;
  color: var(--cz-ink) !important;
  -webkit-text-fill-color: var(--cz-ink);
}

/* Pay in full / Pay partially toggle */
#cleenzy-invoice-root .cleenzy-pay-toggle button {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  background: #fff !important;
  color: var(--cz-ink) !important;
  -webkit-text-fill-color: var(--cz-ink);
  border: 1px solid var(--cz-line) !important;
}
#cleenzy-invoice-root .cleenzy-pay-toggle button:hover,
#cleenzy-invoice-root .cleenzy-pay-toggle button:focus {
  background: #f3f6fa !important;
  color: var(--cz-ink) !important;
  -webkit-text-fill-color: var(--cz-ink);
}
#cleenzy-invoice-root .cleenzy-pay-toggle button.active,
#cleenzy-invoice-root .cleenzy-pay-toggle button.active:hover,
#cleenzy-invoice-root .cleenzy-pay-toggle button.active:focus {
  background: var(--cz-blue) !important;
  color: #fff !important;
  -webkit-text-fill-color: #fff;
  border-color: var(--cz-blue) !important;
}

/* ==========================================================================
 * 2. PRINT ISOLATION  (Download / print invoice, Ctrl+P, "Save as PDF")
 * --------------------------------------------------------------------------
 * public/js/invoice-print.js tags every element that is NOT the invoice with
 * .cleenzy-print-hide, and the invoice's ancestor wrappers with
 * .cleenzy-print-keep (so their padding/height/position can't push the
 * invoice down the page). The classes only take effect when printing.
 * ========================================================================== */
@page { size: A4; margin: 0; } /* margin 0 also hides the browser's own header/footer (date + private invoice URL) */

@media print {
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    background: #fff !important;
  }

  .cleenzy-print-hide { display: none !important; }

  .cleenzy-print-keep {
    display: block !important;
    visibility: visible !important;
    position: static !important;
    float: none !important;
    width: auto !important;
    max-width: none !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: none !important;
    box-shadow: none !important;
    overflow: visible !important;
    transform: none !important;
    filter: none !important;
    opacity: 1 !important;
  }
  .cleenzy-print-keep::before,
  .cleenzy-print-keep::after { display: none !important; }

  #cleenzy-invoice-root {
    display: block !important;
    visibility: visible !important;
    position: static !important;
    width: auto !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 16mm !important; /* page margin (real @page margin is 0, see above) */
    border-radius: 0;
    box-shadow: none;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone; /* repeats the padding on page 2+ of long invoices */
  }
  #cleenzy-invoice-root .cleenzy-pay-box,
  #cleenzy-invoice-root .cleenzy-print-btn { display: none !important; }
  #cleenzy-invoice-root table.cleenzy-lines tr,
  #cleenzy-invoice-root .cleenzy-totals { break-inside: avoid; page-break-inside: avoid; }
}
