/*
 * Streamline Customer Portal styles.
 * Loaded only by portal/includes/customer_header.php -- never by the ERP.
 * Brand tokens follow the tenant (CareSure) logo: blue + green on white.
 * Darker shades are used wherever text sits on white or white sits on colour.
 */

html:root {
    --pl-blue: #0b74c9;
    --pl-blue-dark: #075a9c;
    --pl-blue-soft: #e8f3fc;
    --pl-green: #4cae3c;
    --pl-green-dark: #2d7a22;
    --pl-green-soft: #edf8e8;
    --pl-ink: #0f2233;
    --pl-text: #1b2b3a;
    --pl-muted: #52606d;
    --pl-line: #d5dee8;
    --pl-bg: #f3f6f9;
    --pl-surface: #ffffff;
    --pl-amber: #8a5300;
    --pl-amber-soft: #fff3dc;
    --pl-red: #b42318;
    --pl-red-soft: #fdecea;
    --pl-radius: 10px;
    --pl-max: 1200px;
    --pl-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;

    /* Existing portal pages use the shared --sl-* tokens; map them to the portal brand. */
    --sl-primary: var(--pl-blue);
    --sl-success: var(--pl-green-dark);
    --sl-danger: var(--pl-red);
    --sl-warning: var(--pl-amber);
    --sl-border: var(--pl-line);
    --sl-surface: var(--pl-surface);
    --sl-surface-2: #f7f9fb;
    --sl-text: var(--pl-text);
    --sl-text-muted: var(--pl-muted);
    --sl-focus: var(--pl-blue);
}

body.pl-body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--pl-bg);
    color: var(--pl-text);
    font-family: var(--pl-font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

.pl-body *,
.pl-body *::before,
.pl-body *::after {
    box-sizing: border-box;
}

.pl-wrap {
    width: 100%;
    max-width: var(--pl-max);
    margin: 0 auto;
    padding: 0 16px;
}

.pl-body a:focus-visible,
.pl-body button:focus-visible,
.pl-body select:focus-visible {
    outline: 3px solid var(--pl-blue);
    outline-offset: 2px;
}

/* ---------- Header ---------- */
.pl-header {
    background: var(--pl-surface);
    border-top: 4px solid var(--pl-green);
    border-bottom: 1px solid var(--pl-line);
}

.pl-header-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    padding-top: 12px;
    padding-bottom: 12px;
}

.pl-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
    text-decoration: none;
    color: inherit;
}

.pl-brand img {
    display: block;
    height: auto;
    width: auto;
    max-height: 52px;
    max-width: 220px;
    object-fit: contain;
}

.pl-brand-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--pl-blue-dark);
}

.pl-customer-name {
    padding-left: 16px;
    border-left: 1px solid var(--pl-line);
    font-size: 15px;
    font-weight: 600;
    color: var(--pl-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 320px;
}

.pl-account {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    font-size: 14px;
}

.pl-user-name {
    font-weight: 600;
    color: var(--pl-ink);
}

.pl-site-form {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.pl-site-form label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
}

.pl-select {
    min-height: 40px;
    max-width: 260px;
    padding: 6px 10px;
    border: 1px solid var(--pl-line);
    border-radius: 8px;
    background: var(--pl-surface);
    color: var(--pl-ink);
    font: inherit;
    font-size: 14px;
}

.pl-nav {
    border-top: 1px solid var(--pl-line);
}

.pl-nav ul {
    display: flex;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.pl-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 48px;
    padding: 0 14px;
    border-bottom: 3px solid transparent;
    color: var(--pl-text);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.pl-nav a:hover {
    color: var(--pl-blue-dark);
}

.pl-nav a[aria-current="page"] {
    color: var(--pl-blue-dark);
    border-bottom-color: var(--pl-blue);
}

/* ---------- Page ---------- */
.pl-main {
    flex: 1 0 auto;
    padding-top: 24px;
    padding-bottom: 40px;
}

.pl-page-title {
    margin: 0 0 20px;
    font-size: 26px;
    font-weight: 700;
    line-height: 1.25;
    color: var(--pl-ink);
}

.pl-flash {
    margin-bottom: 20px;
    padding: 12px 16px;
    border: 1px solid var(--pl-line);
    border-left-width: 4px;
    border-radius: var(--pl-radius);
    background: var(--pl-surface);
    font-weight: 500;
}

.pl-flash--success { border-left-color: var(--pl-green); }
.pl-flash--warning { border-left-color: #e0a000; }
.pl-flash--danger { border-left-color: var(--pl-red); }

.pl-section {
    margin-bottom: 24px;
    border: 1px solid var(--pl-line);
    border-radius: var(--pl-radius);
    background: var(--pl-surface);
}

.pl-section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--pl-line);
}

.pl-section-head h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--pl-ink);
}

.pl-section-body {
    padding: 16px 18px;
}

.pl-empty {
    margin: 0;
    padding: 20px 18px;
    color: var(--pl-muted);
}

.pl-grid-2 {
    display: grid;
    gap: 24px;
    grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 900px) {
    .pl-grid-2 {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }
}

.pl-grid-2 > .pl-section {
    margin-bottom: 0;
}

.pl-stack {
    display: grid;
    gap: 24px;
    margin-bottom: 24px;
}

/* ---------- Summary tiles ---------- */
.pl-stats {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    margin-bottom: 24px;
}

.pl-stat {
    display: block;
    padding: 14px 16px;
    border: 1px solid var(--pl-line);
    border-top: 4px solid var(--pl-blue);
    border-radius: var(--pl-radius);
    background: var(--pl-surface);
    color: inherit;
    text-decoration: none;
}

a.pl-stat:hover {
    border-color: var(--pl-blue);
}

.pl-stat--green { border-top-color: var(--pl-green); }
.pl-stat--attention { border-top-color: #e0a000; }

.pl-stat-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--pl-muted);
}

.pl-stat-value {
    margin-top: 4px;
    font-size: 26px;
    font-weight: 700;
    color: var(--pl-ink);
    line-height: 1.2;
}

.pl-stat-detail {
    margin-top: 2px;
    font-size: 14px;
    color: var(--pl-text);
}

/* ---------- Lists (upcoming, activity) ---------- */
.pl-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.pl-list li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 6px 16px;
    padding: 12px 18px;
    border-top: 1px solid var(--pl-line);
}

.pl-list li:first-child {
    border-top: 0;
}

.pl-list-main {
    min-width: 0;
}

.pl-list-title {
    font-weight: 600;
    color: var(--pl-ink);
}

.pl-list-title a {
    color: var(--pl-blue-dark);
    text-decoration: none;
}

.pl-list-title a:hover {
    text-decoration: underline;
}

.pl-body .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.pl-list-meta {
    font-size: 14px;
    color: var(--pl-muted);
}

.pl-list-date {
    font-size: 14px;
    font-weight: 600;
    color: var(--pl-text);
    white-space: nowrap;
}

/* ---------- Badges ---------- */
.pl-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border: 1px solid var(--pl-line);
    border-radius: 999px;
    background: #f1f4f7;
    color: var(--pl-text);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.6;
    white-space: nowrap;
}

.pl-badge--success { border-color: #b9dfb0; background: var(--pl-green-soft); color: var(--pl-green-dark); }
.pl-badge--warning { border-color: #f0cf8e; background: var(--pl-amber-soft); color: var(--pl-amber); }
.pl-badge--danger { border-color: #f3b8b2; background: var(--pl-red-soft); color: var(--pl-red); }
.pl-badge--info { border-color: #b6d7f2; background: var(--pl-blue-soft); color: var(--pl-blue-dark); }

/* ---------- Buttons ---------- */
.pl-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 16px;
    border: 1px solid var(--pl-blue);
    border-radius: 8px;
    background: var(--pl-surface);
    color: var(--pl-blue-dark);
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.pl-btn:hover {
    background: var(--pl-blue-soft);
}

.pl-btn--primary {
    background: var(--pl-blue);
    color: #ffffff;
}

.pl-btn--primary:hover {
    background: var(--pl-blue-dark);
}

.pl-btn--green {
    border-color: var(--pl-green-dark);
    background: var(--pl-green-dark);
    color: #ffffff;
}

.pl-btn--green:hover {
    background: #22611a;
}

.pl-btn--quiet {
    border-color: var(--pl-line);
    color: var(--pl-text);
}

.pl-btn[disabled],
.pl-btn--disabled {
    border-style: dashed;
    border-color: var(--pl-line);
    background: #f7f9fb;
    color: var(--pl-muted);
    cursor: default;
}

.pl-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

/* ---------- Tables (become stacked rows on narrow screens) ---------- */
.pl-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.pl-table th,
.pl-table td {
    padding: 11px 18px;
    border-top: 1px solid var(--pl-line);
    text-align: left;
    vertical-align: middle;
}

.pl-table thead th {
    border-top: 0;
    background: #f7f9fb;
    color: var(--pl-muted);
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.pl-table td.pl-num,
.pl-table th.pl-num {
    text-align: right;
    white-space: nowrap;
}

.pl-table td.pl-cell-actions {
    text-align: right;
    white-space: nowrap;
}

.pl-table .pl-strong {
    font-weight: 700;
    color: var(--pl-ink);
}

.pl-table a.pl-strong {
    color: var(--pl-blue-dark);
    text-decoration: none;
}

.pl-table a.pl-strong:hover {
    text-decoration: underline;
}

.pl-sort {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 32px;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.pl-sort::after {
    content: "\2195";
    font-size: 11px;
    opacity: 0.55;
}

.pl-sort[data-dir="asc"]::after { content: "\2191"; opacity: 1; }
.pl-sort[data-dir="desc"]::after { content: "\2193"; opacity: 1; }

.pl-group-title {
    margin: 0;
    padding: 12px 18px;
    border-top: 1px solid var(--pl-line);
    background: var(--pl-blue-soft);
    color: var(--pl-blue-dark);
    font-size: 15px;
    font-weight: 700;
}

.pl-group-title:first-child {
    border-top: 0;
}

.pl-group-count {
    margin-left: 6px;
    color: var(--pl-muted);
    font-weight: 600;
}

@media (max-width: 760px) {
    .pl-table thead {
        display: none;
    }

    .pl-table,
    .pl-table tbody,
    .pl-table td {
        display: block;
        width: 100%;
    }

    /* Each row becomes a compact card led by its primary cell. */
    .pl-table tr {
        display: flex;
        flex-direction: column;
        width: 100%;
        padding: 10px 16px;
        border-top: 1px solid var(--pl-line);
    }

    .pl-table td.pl-cell-primary {
        order: -1;
    }

    .pl-table tbody tr:first-child {
        border-top: 0;
    }

    .pl-table td {
        display: flex;
        justify-content: space-between;
        gap: 16px;
        padding: 4px 0;
        border-top: 0;
        text-align: right;
    }

    .pl-table td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--pl-muted);
        font-weight: 600;
        text-align: left;
    }

    .pl-table td.pl-cell-primary {
        justify-content: flex-start;
        text-align: left;
        font-size: 15px;
    }

    .pl-table td.pl-cell-primary::before,
    .pl-table td.pl-cell-actions::before {
        content: none;
    }

    .pl-table td.pl-cell-actions {
        justify-content: flex-start;
        padding-top: 8px;
    }

    .pl-table td:empty {
        display: none;
    }
}

/* ---------- Invoice payment ---------- */
.pl-cell-select {
    width: 44px;
}

.pl-check {
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--pl-green-dark);
    cursor: pointer;
}

.pl-pay-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    padding: 14px 18px;
    border-top: 1px solid var(--pl-line);
    background: #f7f9fb;
}

.pl-pay-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 24px;
    font-size: 15px;
}

.pl-pay-summary strong {
    color: var(--pl-ink);
}

/* ---------- Forms ---------- */
.pl-form-section {
    max-width: 760px;
}

.pl-form {
    display: grid;
    gap: 16px;
}

.pl-label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 700;
    color: var(--pl-ink);
}

.pl-input {
    display: block;
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid #b9c6d3;
    border-radius: 8px;
    background: var(--pl-surface);
    color: var(--pl-ink);
    font: inherit;
}

.pl-input:focus {
    border-color: var(--pl-blue);
    outline: 3px solid var(--pl-blue-soft);
}

.pl-textarea {
    min-height: 160px;
    resize: vertical;
}

/* ---------- Footer ---------- */
.pl-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--pl-line);
    background: var(--pl-surface);
    color: var(--pl-muted);
    font-size: 14px;
}

.pl-footer .pl-wrap {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 24px;
    padding-top: 18px;
    padding-bottom: 18px;
}

.pl-footer-contact {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
}

.pl-footer-contact strong {
    color: var(--pl-ink);
}

.pl-footer a {
    color: var(--pl-blue-dark);
    font-weight: 600;
    text-decoration: none;
}

.pl-footer a:hover {
    text-decoration: underline;
}

.pl-powered {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--pl-muted);
}

.pl-powered img {
    display: block;
    height: 18px;
    width: auto;
    opacity: 0.85;
}

/* ---------- Narrow screens ---------- */
@media (max-width: 640px) {
    .pl-brand img {
        max-height: 40px;
        max-width: 160px;
    }

    .pl-customer-name {
        max-width: 60vw;
        font-size: 14px;
        padding-left: 12px;
    }

    .pl-account {
        width: 100%;
        gap: 8px;
    }

    .pl-account .pl-btn {
        min-height: 40px;
        padding: 6px 12px;
        font-size: 13px;
    }

    .pl-user-name {
        width: 100%;
        order: -1;
    }

    .pl-site-form {
        flex: 1 1 100%;
    }

    /* All sections stay visible on phones instead of hiding in a scroller. */
    .pl-nav ul {
        flex-wrap: wrap;
        overflow: visible;
        gap: 0 2px;
    }

    .pl-nav a {
        min-height: 44px;
        padding: 0 10px;
        font-size: 14px;
    }

    .pl-select {
        flex: 1 1 auto;
        max-width: none;
        min-height: 44px;
    }

    .pl-page-title {
        font-size: 22px;
    }

    .pl-btn {
        min-height: 44px;
    }
}
