/* Billing Hub (admin) & public payment page.
   Shares the main app's navy/red brand via CSS variables, with hex fallbacks
   so pay.php (which does not load styles.css) still renders the same colors.
   Admin-side buttons/links always carry .btn-primary-sm / .btn-outline-sm
   (defined in styles.css) — this file must not add a higher-specificity
   `button` element selector inside .billing-panel/.billing-dialog, or it
   silently strips that theming back to a flat default look. Only the public
   payment page (no styles.css loaded) gets its own default button style. */

.billing-panel {
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border-color, #d1d5db);
  border-radius: 12px;
  padding: 24px;
  color: var(--text-main, #1f2937);
  font: 16px/1.6 var(--font-sans, system-ui, sans-serif);
}
.billing-panel h2 { font-size: 1.25rem; margin: 0; }
.billing-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.billing-toolbar h2 { margin-right: auto; }
.billing-toolbar [aria-pressed=true] {
  background: var(--primary-navy, #1a2b4c);
  border-color: var(--primary-navy, #1a2b4c);
  color: #ffffff;
}

.billing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; margin: 16px 0; }
.billing-card {
  border: 1px solid var(--border-color, #d1d5db);
  border-radius: 12px;
  padding: 18px;
  margin: 12px 0;
  background: var(--bg-app, #f8fafc);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
}
.billing-card h3 { margin: 0; color: var(--primary-navy, #1a2b4c); }

.billing-field { display: flex; flex-direction: column; gap: 5px; margin: 12px 0; }
.billing-field input, .billing-field select, .billing-field textarea,
.billing-toolbar input, .billing-toolbar select {
  padding: 10px;
  border: 1px solid var(--border-color, #94a3b8);
  border-radius: 6px;
  font: inherit;
  min-width: 0;
  box-sizing: border-box;
  max-width: 100%;
  background: #ffffff;
  color: var(--text-main, #172b4d);
}
.billing-field textarea { min-height: 160px; }

.billing-panel button:disabled, #billing-dialog button:disabled, .pay-page button:disabled {
  opacity: .5;
  cursor: wait;
}

.billing-panel [role=alert], #billing-dialog [role=alert] {
  color: #991b1b;
  background: #fef2f2;
  padding: 12px;
  border-radius: 8px;
}
.billing-panel [hidden], #billing-dialog [hidden] { display: none; }
.billing-warning {
  color: #854d0e;
  background: #fefce8;
  border: 1px solid #fde68a;
  padding: 12px;
  border-radius: 8px;
}

.billing-table-scroll { overflow: auto; }
.billing-table { border-collapse: collapse; width: 100%; text-align: left; }
.billing-table th, .billing-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border-color, #e2e8f0);
  vertical-align: top;
}

/* Billing dialog reuses the app's own .modal-overlay/.modal-card/.modal-header
   system (see styles.css) instead of a native <dialog>. This is what every
   other modal in the admin dashboard uses; matching it here — rather than
   maintaining a look-alike — guarantees identical centering and chrome
   without depending on a browser's native <dialog> centering/top-layer
   behavior, which some in-app/WebView browsers render inconsistently. */
#billing-dialog .modal-card {
  max-width: 620px;
  color: var(--text-main, #172b4d);
  font: 16px/1.6 var(--font-sans, system-ui, sans-serif);
}
#billing-dialog dd { margin: 0 0 10px; overflow-wrap: anywhere; }
#billing-dialog dt { color: var(--text-muted, #64748b); }
#billing-dialog input[type=checkbox] { width: 20px; height: 20px; vertical-align: middle; }

.billing-qr { max-width: 100%; width: 260px; height: auto; image-rendering: pixelated; }

/* ====================================================================
   Public payment page (pay.php). Classes are prefixed pay- because this
   stylesheet is also loaded on the admin dashboard (index.html) alongside
   styles.css, which already defines its own unrelated .card / .brand /
   .btn-line — an unprefixed name here would silently collide with those.
   No Google Fonts: pay.php's CSP intentionally allows zero third-party
   requests (same reasoning as the locally-vendored QR library), so this
   uses a Thai-capable system font stack instead of an external face.
   ==================================================================== */
.pay-page {
  background: var(--bg-app, #f4f5f8);
  margin: 0;
  padding: 16px 14px 32px;
  font-family: 'Segoe UI', 'Leelawadee UI', 'Noto Sans Thai', system-ui, -apple-system, sans-serif;
  color: var(--text-main, #1f2937);
}
.pay-page * { box-sizing: border-box; }
.pay-page svg { display: block; }
.pay-container { max-width: 440px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.pay-hr { border: none; border-top: 1px solid var(--border-color, #d1d5db); margin: 14px 0; }

.pay-topbar { display: flex; align-items: center; gap: 9px; padding: 0 2px; }
.pay-brand-mark {
  width: 27px; height: 27px; border-radius: 8px; flex: none;
  background: linear-gradient(155deg, var(--primary-navy, #1a2b4c), var(--navy-dark, #0f1a30));
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .86rem;
}
.pay-brand-name { font-weight: 600; font-size: 1rem; }

/* Stepper: only rendered while the invoice is walking pay -> report -> confirm. */
.pay-stepper { display: flex; align-items: center; padding: 0 2px; }
.pay-step { display: flex; align-items: center; gap: 6px; flex: 1; }
.pay-step:last-child { flex: none; }
.pay-step-dot {
  width: 21px; height: 21px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 600;
  background: var(--bg-app, #f4f5f8); color: #8a94a3; border: 1.5px solid var(--border-color, #d1d5db);
}
.pay-step-label { font-size: .72rem; color: #8a94a3; white-space: nowrap; }
.pay-step-line { height: 2px; flex: 1; background: var(--border-color, #d1d5db); margin: 0 4px; border-radius: 2px; }
.pay-step.is-done .pay-step-dot { background: var(--primary-navy, #1a2b4c); border-color: var(--primary-navy, #1a2b4c); color: #fff; }
.pay-step.is-done .pay-step-label { color: var(--text-muted, #6b7280); }
.pay-step.is-active .pay-step-dot { background: #0284c7; border-color: #0284c7; color: #fff; }
.pay-step.is-active .pay-step-label { color: var(--text-main, #1f2937); font-weight: 600; }
.pay-step-line.is-done { background: var(--primary-navy, #1a2b4c); }

/* Hero invoice summary */
.pay-hero { background: #fff; border: 1px solid var(--border-color, #d1d5db); border-radius: 12px; box-shadow: 0 4px 12px rgba(16,24,39,.05); overflow: hidden; }
.pay-hero::before { content: ""; display: block; height: 3px; background: linear-gradient(90deg, var(--primary-navy, #1a2b4c), #0284c7); }
.pay-hero-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.pay-hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.pay-invoice-id { font-size: .76rem; color: #8a94a3; letter-spacing: .02em; font-variant-numeric: tabular-nums; }
.pay-status-pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; flex: none; }
.pay-status-pill.pending { background: #fef3c7; color: #b45309; border: 1px solid #fde68a; }
.pay-status-pill.review { background: #eef2fc; color: var(--primary-navy, #1a2b4c); border: 1px solid var(--border-color, #d1d5db); }
.pay-status-pill.paid { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.pay-status-pill.closed { background: var(--bg-app, #f4f5f8); color: var(--text-muted, #6b7280); border: 1px solid var(--border-color, #d1d5db); }
.pay-status-pill .pay-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

.pay-student-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.pay-student-ico { width: 18px; height: 18px; flex: none; color: #0284c7; }
.pay-student-info { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.pay-student-label { color: #64748b; font-size: .88rem; font-weight: 500; }
.pay-student-name { font-weight: 600; color: #0f172a; font-size: .98rem; }

.pay-item-row { display: flex; align-items: center; gap: 8px; }
.pay-item-ico { width: 19px; height: 19px; flex: none; color: #0284c7; }
.pay-item-name { font-size: 1.05rem; font-weight: 600; }
.pay-amount-row { display: flex; align-items: baseline; gap: 3px; }
.pay-amount-currency { font-weight: 600; font-size: 1.1rem; color: var(--text-muted, #6b7280); }
.pay-amount { font-weight: 700; font-size: 2.35rem; line-height: 1; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.pay-points-line { font-size: .8rem; color: var(--text-muted, #6b7280); font-weight: 600; }
.pay-points-line span { color: #8a94a3; font-weight: 500; }

/* Generic section card */
.pay-card { background: #fff; border: 1px solid var(--border-color, #d1d5db); border-radius: 12px; box-shadow: 0 4px 12px rgba(16,24,39,.05); padding: 15px; }
.pay-card + .pay-card { margin-top: 10px; }
.pay-text-center { text-align: center; }
.pay-card-title { display: flex; align-items: center; gap: 8px; font-size: 1rem; font-weight: 600; margin-bottom: 10px; }
.pay-card-title .pay-ico { width: 18px; height: 18px; flex: none; color: #0284c7; }
.pay-card-note { font-size: .78rem; color: #8a94a3; line-height: 1.5; margin-top: 8px; }

/* Payment method tabs */
.pay-method-tabs { display: flex; gap: 4px; background: var(--bg-app, #f4f5f8); padding: 3px; border-radius: 9px; margin-bottom: 11px; }
.pay-method-tab { flex: 1; border: none; background: transparent; padding: 7px 6px; border-radius: 7px; cursor: pointer; font: inherit; font-size: .85rem; font-weight: 600; color: var(--text-muted, #6b7280); }
.pay-method-tab.active { background: #fff; color: var(--primary-navy, #1a2b4c); box-shadow: 0 4px 12px rgba(16,24,39,.05); }
.pay-method-panel { display: none; }
.pay-method-panel.active { display: block; }

/* Official Thai QR Payment Card - Compact */
.pay-qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.pay-qr-card {
  width: 100%;
  max-width: 280px;
  background: #ffffff;
  border: 1px solid var(--border-color, #d1d5db);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(28, 55, 96, 0.08);
}
.pay-qr-card-header {
  background: #1c3760;
  padding: 7px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pay-qr-brand-logo {
  height: 20px;
  width: auto;
  display: block;
}
.pay-qr-card-body {
  padding: 10px 14px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.pay-qr-promptpay-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.pay-qr-promptpay-logo {
  height: 26px;
  width: auto;
  display: block;
}
.pay-qr-frame {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
}
.pay-qr-frame img, .pay-qr-frame canvas {
  display: block;
  width: 175px;
  height: 175px;
  image-rendering: pixelated;
  border-radius: 4px;
}
.pay-qr-download {
  position: absolute; top: -6px; right: -6px; width: 26px; height: 26px; border-radius: 50%;
  border: 1px solid var(--border-color, #d1d5db); background: #fff; color: #1c3760;
  display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 4px 12px rgba(16,24,39,.08);
  text-decoration: none;
  transition: transform 0.15s ease;
}
.pay-qr-download:hover { transform: scale(1.08); }
.pay-qr-download svg { width: 13px; height: 13px; }

/* Recipient details in standee hierarchy */
.pay-qr-account-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  width: 100%;
  gap: 2px;
  margin-top: 1px;
}
.pay-qr-account-brand {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1c3760;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.pay-qr-account-name {
  font-size: .82rem;
  color: #1f2937;
  word-break: break-word;
  line-height: 1.25;
}
.pay-qr-account-name strong {
  font-weight: 600;
}
.pay-qr-account-num {
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
  color: #6b7280;
  line-height: 1.25;
}

/* Captions and Actions */
.pay-qr-caption {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: .72rem;
  color: #6b7280;
  text-align: center;
  max-width: 280px;
  line-height: 1.3;
}
.pay-qr-caption svg { width: 12px; height: 12px; flex: none; color: #1c3760; }

.pay-qr-actions {
  width: 100%;
  max-width: 280px;
}
.pay-btn-save-qr {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1.5px solid #1c3760;
  background: #f0f7ff;
  color: #1c3760;
  font-size: .82rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  box-sizing: border-box;
  transition: all 0.15s ease;
}
.pay-btn-save-qr:hover {
  background: #1c3760;
  color: #ffffff;
}
.pay-btn-save-qr svg {
  width: 15px;
  height: 15px;
  flex: none;
}

.pay-bank-row { display: flex; align-items: center; gap: 10px; padding: 11px; border: 1px solid var(--border-color, #d1d5db); border-radius: 10px; background: var(--bg-app, #f4f5f8); }
.pay-bank-row + .pay-bank-row { margin-top: 10px; }
.pay-bank-logo { width: 36px; height: 36px; border-radius: 9px; flex: none; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: .68rem; background: #64748b; }
/* Approximate real Thai bank brand colors, cosmetic only. pay.php's CSP
   (style-src 'self', no unsafe-inline) blocks inline style="" entirely, so
   these are picked by class (bank-<CODE>) rather than set inline per row. */
.pay-bank-logo.bank-KBANK { background: #00a950; }
.pay-bank-logo.bank-SCB { background: #4e2a84; }
.pay-bank-logo.bank-BBL { background: #1e4598; }
.pay-bank-logo.bank-KTB { background: #12719e; }
.pay-bank-logo.bank-TTB { background: #003b74; }
.pay-bank-logo.bank-BAY { background: #fec43b; color: #3a2a00; }
.pay-bank-logo.bank-GSB { background: #eb198d; }
.pay-bank-logo.bank-BAAC { background: #4c9a2a; }
.pay-bank-logo.bank-CIMB { background: #7e2f36; }
.pay-bank-logo.bank-UOB { background: #0b3979; }
.pay-bank-logo.bank-KKP { background: #5c2d91; }
.pay-bank-logo.bank-TISCO { background: #f68b1f; }
.pay-bank-logo.bank-LHB { background: #048142; }
.pay-bank-info { flex: 1; min-width: 0; }
.pay-bank-name { font-weight: 600; font-size: .88rem; }
.pay-bank-acc { font-variant-numeric: tabular-nums; letter-spacing: .02em; font-size: .96rem; }
.pay-bank-owner { color: #8a94a3; font-size: .76rem; }

.pay-btn-ghost { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-color, #d1d5db); background: #fff; color: var(--primary-navy, #1a2b4c); font: inherit; font-weight: 600; font-size: .8rem; padding: 8px 13px; border-radius: 8px; cursor: pointer; }
.pay-btn-ghost svg { width: 14px; height: 14px; }
.pay-btn-ghost.copied { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.pay-btn-ghost--full { width: 100%; justify-content: center; margin-top: 12px; padding: 10px; }
.pay-page button:focus-visible, .pay-page input:focus-visible, .pay-page select:focus-visible, .pay-page a:focus-visible {
  outline: 2px solid #0284c7; outline-offset: 2px;
}

/* LINE quick-send: fixed brand green, unrelated to either site palette */
.pay-btn-line { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; background: #06c755; color: #fff; border: none; border-radius: 9px; padding: 12px; cursor: pointer; font: inherit; font-weight: 700; font-size: .94rem; text-decoration: none; }
.pay-btn-line:hover { background: #05a648; }
.pay-btn-line svg { width: 18px; height: 18px; flex: none; }
.pay-line-caption { text-align: center; font-size: .75rem; color: #8a94a3; margin-top: 7px; }

/* Report-transfer form */
.pay-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 9px; }
.pay-field label { font-size: .8rem; font-weight: 600; color: var(--text-muted, #6b7280); }
.pay-field label .pay-req { color: #b45309; margin-left: 2px; }
.pay-field input, .pay-field select { padding: 9px 10px; border: 1px solid var(--border-color, #d1d5db); border-radius: 8px; font: inherit; font-size: .93rem; background: #fff; color: var(--text-main, #1f2937); width: 100%; }
.pay-field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pay-btn-primary { width: 100%; background: #0284c7; color: #fff; border: none; border-radius: 9px; padding: 12px; font: inherit; font-weight: 700; font-size: .96rem; cursor: pointer; }
.pay-btn-primary:hover { background: #0369a1; }

/* Resting states: paid / cancelled / expired / invalid-link */
.pay-state-icon { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto 2px; }
.pay-state-icon svg { width: 23px; height: 23px; }
.pay-state-icon.success { background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857; }
.pay-state-icon.neutral { background: var(--bg-app, #f4f5f8); border: 1px solid var(--border-color, #d1d5db); color: var(--text-muted, #6b7280); }
.pay-state-icon.warn { background: #fef3c7; border: 1px solid #fde68a; color: #b45309; }
.pay-state-title { text-align: center; font-weight: 700; font-size: 1rem; }
.pay-state-meta { text-align: center; color: #8a94a3; font-size: .8rem; margin-top: 2px; }

.pay-review-box { display: flex; align-items: flex-start; gap: 10px; }
.pay-review-ico { width: 32px; height: 32px; border-radius: 9px; background: #eef2fc; color: var(--primary-navy, #1a2b4c); display: flex; align-items: center; justify-content: center; flex: none; }
.pay-review-ico svg { width: 16px; height: 16px; }
.pay-review-title { font-weight: 600; font-size: .92rem; }

.pay-footer-note { text-align: center; color: #8a94a3; font-size: .74rem; line-height: 1.5; padding: 0 8px; margin: 0; }

@media (max-width: 600px) {
  .billing-panel { padding: 15px; }
  .billing-toolbar { align-items: stretch; }
  .billing-toolbar button { flex-grow: 1; }
}

@media print {
  body:has(#billing-dialog:not(.hidden)) > *:not(#billing-dialog) { display: none !important; }
  #billing-dialog:not(.hidden) { position: static !important; background: none !important; padding: 0 !important; height: auto !important; }
  #billing-dialog .modal-card { max-width: 100%; max-height: none; box-shadow: none; }
  #billing-dialog .modal-header, #billing-dialog button { display: none !important; }
}
