/* ============================================================
   Global App Styles – app.css (UPDATED)
   - Includes Billing Preview table fixes + optional improvements
   ============================================================ */

html, body {
    height: auto;
    overflow-x: hidden; /* keep global default; preview page overrides below */
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background: #f7f9fc;
    margin: 0;
    padding: 0;
    color: #222;
}

/*
 ⚠️ IMPORTANT:
 Do NOT restrict overflow on containers.
 Bootstrap modals must escape the layout.
*/
.container {
    max-width: 900px;
    margin: 60px auto;
    background: #fff;
    padding: 40px;
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
    overflow: visible; /* critical */
}

h1, h2, h3 {
    color: #003366;
    margin-top: 0;
}

p {
    color: #444;
}

/* ============================================================
   HEADER LAYOUT (CLEAN HORIZONTAL TOOLBAR)
   ============================================================ */

.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.header-left {
    flex: 1;
}

.header-right {
    display: flex;
    align-items: flex-start;
}

/* Action toolbar below title */
.header-actions-links {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e5e5e5;
}

/* Link styling */
.add-link {
    font-size: 0.9em;
    text-decoration: none;
    color: #2c7be5;
    font-weight: 500;
}

.add-link:hover {
    text-decoration: underline;
}


/* ============================================================
   Cards & Layout
   ============================================================ */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
    margin-top: 30px;
}

.card {
    border: 1px solid #ddd;
    border-radius: 6px;
    padding: 20px;
    background: #fafafa;
    overflow: visible; /* critical for modals */
}

.card h3 {
    color: #2c7be5;
}

.card a {
    display: inline-block;
    margin-top: 10px;
    text-decoration: none;
    background: #2c7be5;
    color: #fff;
    padding: 8px 14px;
    border-radius: 4px;
    font-size: 14px;
}

.card a:hover {
    background: #1a5fc1;
}

/* ============================================================
   Forms
   ============================================================ */

label {
    font-weight: bold;
    display: block;
    margin-top: 20px;
}

input, textarea, select {
    width: 100%;
    padding: 8px;
    margin-top: 8px;
    font-size: 14px;
}

textarea {
    min-height: 280px;
    font-family: Consolas, monospace;
}

button {
    margin-top: 25px;
    background: #2c7be5;
    color: #fff;
    border: none;
    padding: 10px 18px;
    font-size: 14px;
    border-radius: 4px;
    cursor: pointer;
}

button:hover {
    background: #1a5fc1;
}

/* Optional improvement: nicer focus states */
input:focus, textarea:focus, select:focus, button:focus {
    outline: 2px solid rgba(44,123,229,0.25);
    outline-offset: 2px;
}

/* ============================================================
   Notices
   ============================================================ */

.note {
    background: #eef6ff;
    border-left: 5px solid #2c7be5;
    padding: 12px 15px;
    margin: 20px 0;
    font-size: 14px;
}

.warning {
    background: #fff3cd;
    border-left: 5px solid #ff9800;
    padding: 12px 15px;
    margin: 20px 0;
    font-size: 14px;
}

.success {
    background: #e8f5e9;
    border-left: 5px solid #4caf50;
    padding: 12px 15px;
    margin: 20px 0;
    font-size: 14px;
}

/* ============================================================
   Tables (Compact, Ledger-style)
   ============================================================ */

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th,
.table td {
    padding: 4px 6px;
    font-size: 0.88em;
    vertical-align: middle;
    border-bottom: 1px solid #e5e5e5;
}

.table th {
    font-weight: bold;
    text-align: left;
    color: #333;
}

.table td.right,
.table th.right {
    text-align: right;
}

.table tr:hover {
    background: #f6f9ff;
}

/* ============================================================
   Inline Action Icons
   ============================================================ */

.actions-icons {
    white-space: nowrap;
}

.actions-icons .icon {
    display: inline-block;
    margin-left: 6px;
    font-size: 1.05em;
    text-decoration: none;
    cursor: pointer;
}

.actions-icons .icon.edit {
    color: #0a58ca;
}

.actions-icons .icon.delete {
    color: #b00020;
}

.actions-icons .icon:hover {
    opacity: 0.8;
}

/* ============================================================
   Pagination
   ============================================================ */

.pagination {
    margin-top: 10px;
}

.pagination a {
    padding: 4px 8px;
    margin: 0 2px;
    border: 1px solid #ccc;
    text-decoration: none;
    font-size: 0.85em;
    color: #333;
}

.pagination a.active {
    background: #004b8d;
    color: #fff;
}



/* ============================================================
   Footer
   ============================================================ */

footer {
    margin-top: 40px;
    font-size: 13px;
    color: #666;
    border-top: 1px solid #ddd;
    padding-top: 15px;
}

/* ============================================================
   BOOTSTRAP MODAL FIXES (CRITICAL)
   ============================================================ */

/* Ensure modal overlays everything */
.modal {
    z-index: 1055;
}

.modal-backdrop {
    z-index: 1050;
}

/* Lock background scroll when modal open */
body.modal-open {
    overflow: hidden !important;
}

/* Proper scrolling inside modal */
.modal-body {
    max-height: calc(100vh - 220px);
    overflow-y: auto;
}

/* Keep footer visible */
.modal-footer {
    position: sticky;
    bottom: 0;
    background: #fff;
    z-index: 10;
    border-top: 1px solid #e5e5e5;
}

/* HST Allowance Modal */
.hst-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99999;
}

.hst-modal .modal-content {
  background: #fff;
  max-width: 1100px;
  margin: 40px auto;
  padding: 16px;
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(0,0,0,.25);
}

/* ============================================================
   Billing Preview Table (ADDED 10FEB2026 - UPDATED)
   ============================================================ */

/*
  IMPORTANT:
  Your global `overflow-x: hidden` on body prevents horizontal scroll.
  We keep global behavior, but explicitly re-enable it ONLY for this page
  by adding <body class="page-billing-preview"> in billing_preview.php.
*/
body.page-billing-preview {
  overflow-x: auto; /* allow horizontal scroll on preview page */
}

/* Optional improvement: widen the container just for preview page */
body.page-billing-preview .container {
  max-width: 1200px; /* increase if you want */
}

/* Wrapper provides horizontal scroll + vertical scroll (sticky header) */
body.page-billing-preview .table-wrap{
  width: 100%;
  overflow-x: auto !important; /* force scroll even if other rules exist */
  overflow-y: auto;
  max-height: 70vh;            /* keeps header visible on long files */
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;

  /* Optional improvement: smoother scrolling + iOS friendly */
  -webkit-overflow-scrolling: touch;
}

/* The actual table */
body.page-billing-preview .preview-table{
  width: 100%;
  min-width: 1400px;          /* OPTIONAL improvement: less cramped (was 1200px) */
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 14px;
}

body.page-billing-preview .preview-table th,
body.page-billing-preview .preview-table td{
  padding: 8px 10px;
  border-bottom: 1px solid #eef2f7;
  vertical-align: top;
}

body.page-billing-preview .preview-table thead th{
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff;
  border-bottom: 2px solid #e5e7eb;
  font-weight: 600;
  white-space: nowrap;
}

/* Default: keep cells on one line with ellipsis */
body.page-billing-preview .preview-table td{
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Allow wrap for long-text columns */
body.page-billing-preview .preview-table td:nth-child(4),   /* Location */
body.page-billing-preview .preview-table td:nth-child(14),  /* Messages */
body.page-billing-preview .preview-table td:nth-child(17){  /* Provider */
  white-space: normal;
  overflow: visible;
  text-overflow: unset;
  word-break: break-word;
}

/* Column sizing */
body.page-billing-preview .preview-table th:nth-child(1),
body.page-billing-preview .preview-table td:nth-child(1){  width: 110px; } /* Service Date */

body.page-billing-preview .preview-table th:nth-child(2),
body.page-billing-preview .preview-table td:nth-child(2){  width: 80px;  } /* Patient */

body.page-billing-preview .preview-table th:nth-child(3),
body.page-billing-preview .preview-table td:nth-child(3){  width: 95px;  } /* Name */

body.page-billing-preview .preview-table th:nth-child(4),
body.page-billing-preview .preview-table td:nth-child(4){  width: 170px; } /* Location */

body.page-billing-preview .preview-table th:nth-child(5),
body.page-billing-preview .preview-table td:nth-child(5){  width: 110px; } /* Billing Date */

body.page-billing-preview .preview-table th:nth-child(6),
body.page-billing-preview .preview-table td:nth-child(6){  width: 90px;  } /* Code */

body.page-billing-preview .preview-table th:nth-child(7),
body.page-billing-preview .preview-table td:nth-child(7){  width: 80px;  text-align:right; } /* Billed */

body.page-billing-preview .preview-table th:nth-child(8),
body.page-billing-preview .preview-table td:nth-child(8){  width: 80px;  text-align:right; } /* Paid */

body.page-billing-preview .preview-table th:nth-child(9),
body.page-billing-preview .preview-table td:nth-child(9){  width: 70px;  text-align:right; } /* Adj */

body.page-billing-preview .preview-table th:nth-child(10),
body.page-billing-preview .preview-table td:nth-child(10){ width: 60px;  text-align:right; } /* Del */

body.page-billing-preview .preview-table th:nth-child(11),
body.page-billing-preview .preview-table td:nth-child(11){ width: 60px;  } /* Dx */

body.page-billing-preview .preview-table th:nth-child(12),
body.page-billing-preview .preview-table td:nth-child(12){ width: 70px;  } /* Type */

body.page-billing-preview .preview-table th:nth-child(13),
body.page-billing-preview .preview-table td:nth-child(13){ width: 95px;  } /* Invoice # */

body.page-billing-preview .preview-table th:nth-child(14),
body.page-billing-preview .preview-table td:nth-child(14){ width: 280px; } /* Messages (optional improvement) */

body.page-billing-preview .preview-table th:nth-child(15),
body.page-billing-preview .preview-table td:nth-child(15){ width: 130px; } /* Method */

body.page-billing-preview .preview-table th:nth-child(16),
body.page-billing-preview .preview-table td:nth-child(16){ width: 60px;  text-align:right; } /* Qty */

body.page-billing-preview .preview-table th:nth-child(17),
body.page-billing-preview .preview-table td:nth-child(17){ width: 170px; } /* Provider */

/* Zebra rows */
body.page-billing-preview .preview-table tbody tr:nth-child(even){
  background: #fafafa;
}

/* Optional improvement: row hover for readability */
body.page-billing-preview .preview-table tbody tr:hover{
  background: #f6f9ff;
}

/* Optional improvement: make numbers align better */
body.page-billing-preview .preview-table td:nth-child(7),
body.page-billing-preview .preview-table td:nth-child(8),
body.page-billing-preview .preview-table td:nth-child(9),
body.page-billing-preview .preview-table td:nth-child(10),
body.page-billing-preview .preview-table td:nth-child(16){
  font-variant-numeric: tabular-nums;
}
