/* Brand color sampled directly from the Klinik logo (#0080a3). */
:root {
    --brand: #0080a3;
    --brand-dark: #006883;
    --brand-tint: #e3f3f7;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background: #f3f4f6;
    color: #111827;
}

.topbar {
    background: #fff;
    color: #111827;
    height: 64px;
    padding: 0 32px;
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    border-bottom: 1px solid #e5e7eb;
}

.nav-left {
    display: flex;
    align-items: stretch;
    gap: 56px;
}

.brand {
    display: flex;
    align-items: center;
}

.brand-logo {
    height: 34px;
    width: auto;
    display: block;
}

.main-nav {
    display: flex;
    align-items: stretch;
    gap: 40px;
}

/* Underline sits on the bar's own bottom edge (margin-bottom: -1px
   overlaps the topbar's 1px border), like the patient portal header. */
.main-nav a {
    display: flex;
    align-items: center;
    color: #6b7280;
    text-decoration: none;
    font-size: 15px;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    padding: 0 4px;
}

.main-nav a:hover {
    color: #111827;
}

.main-nav a.active {
    color: #111827;
    border-bottom-color: var(--brand);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

.sync-now {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sync-now-status {
    color: #9ca3af;
    font-size: 12px;
    white-space: nowrap;
}

.sync-now-status.is-error {
    color: #b91c1c;
}

.sync-now-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    color: #374151;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}

.sync-now-btn:hover:not(:disabled) {
    border-color: var(--brand);
    color: #111827;
}

.sync-now-btn:disabled {
    cursor: default;
    color: #6b7280;
    background: #f9fafb;
}

.sync-now.is-running .sync-now-btn svg {
    animation: sync-spin 1s linear infinite;
}

@keyframes sync-spin {
    to { transform: rotate(360deg); }
}

.user-menu {
    position: relative;
    display: flex;
    align-items: center;
}

.user-menu summary {
    display: flex;
    align-items: center;
    gap: 6px;
    list-style: none;
    cursor: pointer;
    color: #4b5563;
    font-size: 15px;
}

.user-menu summary::-webkit-details-marker {
    display: none;
}

.user-menu summary:hover {
    color: #111827;
}

.user-menu-panel {
    position: absolute;
    top: calc(100% - 8px);
    right: 0;
    min-width: 170px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 6px 0;
    z-index: 10;
}

.user-menu-panel a {
    display: block;
    padding: 8px 16px;
    color: #374151;
    text-decoration: none;
    font-size: 14px;
}

.user-menu-panel a:hover {
    background: #f3f4f6;
}

@media (max-width: 720px) {
    .topbar { padding: 0 16px; }
    .nav-left { gap: 20px; }
    .main-nav { gap: 16px; }
    .main-nav a { font-size: 13px; }
    .sync-now-status { display: none; }
    .nav-right { gap: 12px; }
}

/* Accounting Dashboard: bills in the range still open in Insta. */
.open-bills-warning {
    margin: 16px 24px 0;
    padding: 10px 14px;
    background: #fffbeb;
    border: 1px solid #fcd34d;
    border-left: 4px solid #d97706;
    border-radius: 6px;
    color: #78350f;
    font-size: 14px;
    line-height: 1.5;
}

.open-bills-warning strong {
    color: #92400e;
}

.range-bar {
    background: #fff;
    padding: 10px 24px;
    display: flex;
    justify-content: flex-end;
    border-bottom: 1px solid #e5e7eb;
}

.range-form {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.range-form label {
    font-size: 13px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.range-form input {
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid #cbd5e1;
}

.range-form button {
    padding: 6px 14px;
    background: var(--brand);
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    align-self: flex-end;
}

.range-form button:hover {
    background: var(--brand-dark);
}

.quick-ranges {
    display: flex;
    gap: 8px;
    align-self: flex-end;
}

.quick-ranges a {
    color: var(--brand);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}

.quick-ranges a:hover {
    text-decoration: underline;
}

.pdf-button {
    margin-left: auto;
    align-self: flex-end;
    padding: 6px 14px;
    border: 1px solid var(--brand);
    border-radius: 4px;
    color: var(--brand);
    background: #fff;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
}

.pdf-button:hover {
    background: var(--brand);
    color: #fff;
}

.kpi-table-section {
    margin: 24px 24px 16px;
}

.kpi-table {
    font-size: 14px;
}

.kpi-table th {
    color: var(--brand-dark);
    font-weight: 600;
    vertical-align: bottom;
}

.kpi-table th.num,
.kpi-table td.num {
    text-align: right;
    white-space: nowrap;
}

.kpi-table-range {
    display: block;
    font-size: 12px;
    font-weight: 400;
    color: #6b7280;
}

.kpi-table td {
    padding: 8px;
}

.kpi-table .kpi-row--key td {
    font-weight: 700;
    background: var(--brand-tint);
}

.kpi-table .kpi-row--sub td {
    font-size: 12px;
    color: #6b7280;
    padding-top: 4px;
    padding-bottom: 4px;
}

.kpi-table .kpi-row--sub td:first-child {
    padding-left: 24px;
}

.table-card {
    background: #fff;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.table-card h2 {
    font-size: 15px;
    margin: 0 0 12px;
}

.tables-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin: 0 24px 24px;
}

.table-card--tall {
    grid-row: span 2;
}

.table-card--full {
    grid-column: 1 / -1;
}

@media (max-width: 720px) {
    .tables-grid {
        grid-template-columns: 1fr;
    }

    .table-card--tall {
        grid-row: auto;
    }
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th, td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid #e5e7eb;
}

th {
    color: #6b7280;
    font-weight: 500;
}

.bar-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bar-list-total {
    display: flex;
    justify-content: space-between;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #e5e7eb;
    font-size: 13px;
    font-weight: 600;
    color: #111827;
}

.bar-row {
    display: grid;
    grid-template-columns: 130px 1fr auto;
    align-items: center;
    gap: 10px;
}

.bar-list--wide-label .bar-row {
    grid-template-columns: 190px 1fr auto;
}

.bar-label {
    font-size: 12px;
    color: #374151;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-track {
    background: #f3f4f6;
    border-radius: 4px;
    height: 20px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    background: var(--brand);
    border-radius: 4px;
}

.bar-value {
    font-size: 12px;
    font-weight: 500;
    color: #111827;
    white-space: nowrap;
}

.no-data {
    font-size: 13px;
    color: #6b7280;
}

.visit-details-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(220px, 1fr));
    gap: 24px;
}

.visit-details-grid h3 {
    font-size: 13px;
    color: var(--brand-dark);
    margin: 0 0 10px;
    font-weight: 600;
}

.visit-detail--col1-row1 {
    grid-column: 1;
    grid-row: 1;
}

.visit-detail--col1-row2 {
    grid-column: 1;
    grid-row: 2;
}

.visit-detail--tall {
    grid-row: span 2;
}

@media (max-width: 900px) {
    .visit-details-grid {
        grid-template-columns: 1fr;
    }

    .visit-detail--col1-row1,
    .visit-detail--col1-row2,
    .visit-detail--tall {
        grid-column: auto;
        grid-row: auto;
    }
}

.voucher-table .num {
    text-align: right;
    white-space: nowrap;
}

.voucher-table .subtotal-row td {
    font-weight: 600;
    background: #f9fafb;
    border-bottom: 1px solid #d1d5db;
}

/* A group's own total, under its rows (Collections by User). */
.voucher-table .group-total-row td {
    font-weight: 600;
    color: #374151;
    border-bottom: 1px solid #d1d5db;
}

/* Heading row for a group (e.g. a store) whose rows follow, indented. */
.voucher-table .store-row td {
    font-weight: 600;
    color: var(--brand-dark);
    padding-top: 14px;
}

.voucher-table td.indent {
    padding-left: 22px;
}

/* A bill's ledger entries, expanded under its row on the Sales Bills page. */
.voucher-table .bill-entries-row > td {
    background: #f9fafb;
    padding: 12px 16px 16px;
    border-bottom: 2px solid #d1d5db;
    white-space: normal;
}

/* Entries Insta later cancelled: shown for reference, not counted. */
.bill-entries-table .entry-inactive td {
    color: #9ca3af;
}

/* The expanded block can be far wider than the screen; keep its text readable without scrolling. */
.bill-entries-row .details-summary,
.bill-entries-row .card-note {
    max-width: 900px;
}

/* Entry posted on a later day than its voucher date (back-dated). */
.voucher-table td.posted-late {
    color: #b45309;
    font-weight: 600;
}

.bill-entries-table .entry-inactive td.posted-late {
    color: #d6a76b;
}

.status-badge {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.status-active {
    background: #dcfce7;
    color: #166534;
}

.status-reversed,
.status-reversal {
    background: #f3f4f6;
    color: #6b7280;
}

.card-note {
    font-size: 12px;
    color: #6b7280;
    margin: 12px 0 0;
}

.drill-link {
    color: var(--brand-dark);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.drill-link:hover {
    color: var(--brand);
}

.details-page {
    margin: 20px 24px 24px;
}

.back-link {
    display: inline-block;
    margin-bottom: 12px;
    color: var(--brand-dark);
    font-size: 13px;
    text-decoration: none;
}

.back-link:hover {
    text-decoration: underline;
}

.details-summary {
    font-size: 13px;
    color: #4b5563;
    margin: -4px 0 12px;
}

.table-scroll {
    overflow-x: auto;
}

.details-table {
    font-size: 12px;
}

.details-table td {
    white-space: nowrap;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 14px;
    font-size: 13px;
    color: #4b5563;
}

.pager a {
    color: var(--brand-dark);
    text-decoration: none;
    font-weight: 500;
}

.pager a:hover {
    text-decoration: underline;
}

.bar-list-aside {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 8px;
    font-size: 12px;
    color: #6b7280;
}

.bar-list-aside small {
    display: block;
    font-size: 11px;
    color: #9ca3af;
}

.bar-list-aside span:last-child {
    white-space: nowrap;
}

.group-actions {
    display: flex;
    gap: 8px;
    margin: -4px 0 10px;
}

.group-actions button {
    font-size: 12px;
    padding: 4px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: #fff;
    color: var(--brand-dark);
    cursor: pointer;
}

.details-table .toggle-cell {
    width: 28px;
    padding-right: 0;
}

.row-toggle {
    width: 20px;
    height: 20px;
    padding: 0;
    border: 1px solid var(--brand);
    border-radius: 4px;
    background: #fff;
    color: var(--brand-dark);
    font-size: 14px;
    font-weight: 600;
    line-height: 18px;
    cursor: pointer;
}

.row-toggle[aria-expanded="true"] {
    background: var(--brand-tint);
}

.details-table .line-row td {
    background: #f9fafb;
    color: #4b5563;
}

.muted {
    color: #9ca3af;
    font-style: italic;
}

/* Doctor details page (accounting_doctor_details.php): Print button and
   a print layout - A4, no nav or buttons, a report header instead. */
.details-toolbar {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
}

.details-toolbar .back-link {
    margin-bottom: 0;
}

.details-toolbar .pdf-button {
    align-self: center;
    cursor: pointer;
}

.doctor-report .details-page .table-card + .table-card {
    margin-top: 16px;
}

.print-header {
    display: none;
}

@media print {
    @page {
        size: A4 portrait;
        margin: 12mm 10mm;
        @bottom-center {
            content: "Page " counter(page) " of " counter(pages);
            font-size: 9px;
            color: #6b7280;
        }
    }

    .doctor-report {
        background: #fff;
        font-size: 11px;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .doctor-report .topbar,
    .doctor-report .details-toolbar,
    .doctor-report .screen-only {
        display: none;
    }

    .doctor-report .details-page {
        margin: 0;
    }

    .doctor-report .print-header {
        display: flex;
        align-items: center;
        gap: 16px;
        padding-bottom: 10px;
        margin-bottom: 14px;
        border-bottom: 2px solid var(--brand);
    }

    .print-header .print-logo {
        height: 40px;
    }

    .print-header h1 {
        font-size: 18px;
        margin: 0 0 2px;
        color: var(--brand-dark);
    }

    .print-header p {
        margin: 0;
        font-size: 11px;
        color: #4b5563;
    }

    .print-header .print-doctor {
        font-size: 14px;
        font-weight: 600;
        color: #111827;
    }

    .doctor-report .table-card {
        box-shadow: none;
        border-radius: 0;
        padding: 0;
    }

    .doctor-report .details-page .table-card + .table-card {
        margin-top: 18px;
    }

    .doctor-report .table-card h2 {
        font-size: 13px;
        margin-bottom: 6px;
        break-after: avoid;
    }

    .doctor-report .table-scroll {
        overflow: visible;
    }

    .doctor-report .voucher-table {
        width: 100%;
        font-size: 10.5px;
    }

    .doctor-report .voucher-table th,
    .doctor-report .voucher-table td {
        padding-top: 3px;
        padding-bottom: 3px;
    }

    .doctor-report .voucher-table tr {
        break-inside: avoid;
    }

    /* Keep a card's heading, the table header and a group's heading row
       with the rows after them instead of alone at the foot of a page. */
    .doctor-report .table-card h2,
    .doctor-report .voucher-table thead,
    .doctor-report .voucher-table .store-row {
        break-after: avoid;
    }

    .doctor-report .voucher-table .store-row td {
        padding-top: 8px;
    }

    .doctor-report .card-note {
        font-size: 9px;
    }
}
