* { box-sizing: border-box; }
body { margin: 0; font-family: Arial, sans-serif; background: #f4f6f8; color: #1f2937; }
a { color: #0f4c81; text-decoration: none; }

.nav { background: #0f172a; color: white; padding: 16px 28px; display: flex; justify-content: space-between; align-items: center; }
.nav a { color: white; margin-left: 18px; }
.brand { font-weight: bold; }
.container { max-width: 1000px; margin: 32px auto; padding: 0 18px; }

.topbar { min-height: 74px; background: white; display: flex; justify-content: space-between; align-items: center; padding: 0 30px; border-bottom: 1px solid #e2e8f0; position: sticky; top: 0; z-index: 5; }
.page-title { font-size: 20px; font-weight: bold; }
.topbar-user { display: flex; align-items: center; gap: 10px; color: #475569; }
.topbar-user span { font-size: 13px; }
.topbar-user strong { color: #0f172a; }
.logout-link { background: #e2e8f0; color: #0f172a; padding: 8px 12px; border-radius: 8px; font-weight: bold; }
.logout-link:hover { background: #cbd5e1; }
.content-area { padding: 28px 30px; }

.card, .welcome-card { background: white; border-radius: 12px; padding: 28px; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08); }
.welcome-card h1 { margin-top: 0; }
.narrow { max-width: 460px; margin: 0 auto; }
label { display: block; margin-top: 14px; font-weight: bold; }
input { width: 100%; padding: 12px; margin-top: 6px; border: 1px solid #cbd5e1; border-radius: 8px; }
button { margin-top: 20px; width: 100%; padding: 12px; background: #0f4c81; color: white; border: 0; border-radius: 8px; font-weight: bold; cursor: pointer; }
button:hover { background: #0b3b64; }
.messages { margin-bottom: 18px; }
.alert { padding: 12px; border-radius: 8px; margin-bottom: 8px; background: #e2e8f0; }
.alert.success { background: #dcfce7; }
.alert.danger { background: #fee2e2; }
.alert.warning { background: #fef3c7; }
.alert.info { background: #dbeafe; }

.grid, .module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-top: 20px; }
.module-card { background: white; padding: 22px; border-radius: 12px; box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06); display: block; min-height: 126px; color: #1f2937; border: 1px solid transparent; }
.module-card:hover { border-color: #0f4c81; transform: translateY(-1px); }
.module-title { display: block; font-weight: bold; margin-bottom: 8px; }
.module-card small { color: #64748b; font-weight: normal; line-height: 1.4; }


/* Global readability and layout protection rules for all current and future modules */
html { font-size: 15px; }
body { overflow-x: hidden; }

h1, h2, h3, h4, h5, h6, p, span, small, label, a, button, th, td, input, select, textarea {
    overflow-wrap: anywhere;
    word-break: normal;
    line-height: 1.35;
}

h1 { font-size: clamp(1.45rem, 2.2vw, 2rem); }
h2 { font-size: clamp(1.25rem, 1.8vw, 1.65rem); }
h3 { font-size: clamp(1.1rem, 1.5vw, 1.35rem); }

.content-area, .card, .welcome-card, .module-card, .form-card, .table-card {
    min-width: 0;
    max-width: 100%;
}

/* Forms: aligned labels and inputs, with text kept readable */
.form-grid {
    display: grid;
    grid-template-columns: minmax(150px, 220px) minmax(220px, 1fr);
    gap: 14px 18px;
    align-items: center;
}

.form-grid label {
    margin-top: 0;
    text-align: right;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
    margin-top: 0;
    min-width: 0;
}

input, select, textarea {
    max-width: 100%;
    font-size: 0.95rem;
}

textarea {
    min-height: 100px;
    resize: vertical;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 20px;
}

.form-actions button,
.form-actions a,
.button-auto {
    width: auto;
    min-width: 130px;
}

/* Tables: columns adapt, long text wraps inside cells, and wide tables scroll on screen */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
    background: white;
}

th, td {
    padding: 10px 12px;
    border-bottom: 1px solid #e2e8f0;
    text-align: left;
    vertical-align: top;
    max-width: 280px;
    white-space: normal;
}

th {
    font-size: 0.86rem;
    color: #334155;
    background: #f8fafc;
}

td {
    font-size: 0.9rem;
}

.table-compact th,
.table-compact td {
    padding: 7px 8px;
    font-size: 0.82rem;
}

.text-nowrap {
    white-space: nowrap;
}

.text-center { text-align: center; }
.text-right { text-align: right; }

/* Print and PDF export rules */
@media print {
    @page {
        size: portrait;
        margin: 12mm;
    }

    body {
        background: white;
        color: #000;
        font-size: 10pt;
        overflow: visible;
    }

    .sidebar,
    .topbar,
    .nav,
    .logout-link,
    .no-print {
        display: none !important;
    }

    .app-shell,
    .main-panel,
    .content-area,
    .container {
        display: block;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto;
    }

    .card,
    .welcome-card,
    .module-card,
    .table-card {
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }

    table {
        table-layout: auto;
        width: 100%;
        page-break-inside: auto;
    }

    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }

    th, td {
        font-size: 8.5pt;
        padding: 5px 6px;
        max-width: none;
        overflow-wrap: anywhere;
    }

    .pdf-landscape {
        page: landscape-page;
    }

    @page landscape-page {
        size: landscape;
        margin: 10mm;
    }

    .pdf-landscape th,
    .pdf-landscape td {
        font-size: 7.5pt;
        padding: 4px 5px;
    }
}

@media (max-width: 640px) {
    html { font-size: 14px; }

    .form-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .form-grid label {
        text-align: left;
    }

    .form-actions {
        justify-content: stretch;
    }

    .form-actions button,
    .form-actions a,
    .button-auto {
        width: 100%;
    }

    th, td {
        max-width: 190px;
        font-size: 0.82rem;
        padding: 8px;
    }
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.button-row {
    display: flex;
    gap: .6rem;
    flex-wrap: wrap;
}
.btn, button, input[type="submit"] {
    display: inline-block;
    background: #1f3b63;
    color: #fff;
    border: 0;
    border-radius: .5rem;
    padding: .7rem 1rem;
    text-decoration: none;
    cursor: pointer;
    font-size: .95rem;
    line-height: 1.2;
}
.btn.secondary { background: #596579; }
.btn.small, button.small { padding: .45rem .7rem; font-size: .85rem; }
.nav-group-title {
    margin: 1rem .75rem .35rem;
    font-size: .78rem;
    font-weight: 700;
    color: #b8c4d6;
    text-transform: uppercase;
    letter-spacing: .05em;
    overflow-wrap: anywhere;
}
.permission-matrix th,
.permission-matrix td {
    text-align: center;
    vertical-align: middle;
    min-width: 74px;
}
.permission-matrix th:first-child,
.permission-matrix td:first-child {
    text-align: left;
    min-width: 190px;
}
.center-cell { text-align: center; }
.inline-role-form {
    display: flex;
    gap: .7rem;
    flex-wrap: wrap;
    align-items: center;
}
.inline-role-form label {
    white-space: nowrap;
    font-size: .9rem;
}
.narrow-card {
    max-width: 760px;
}
.topbar-user small {
    display: block;
    color: #596579;
    font-size: .78rem;
    max-width: 260px;
    overflow-wrap: anywhere;
}

.muted { color: #64748b; margin-top: .25rem; }
.badge {
    display: inline-flex;
    align-items: center;
    padding: .45rem .7rem;
    border-radius: 999px;
    background: #e2e8f0;
    color: #334155;
    font-size: .82rem;
    font-weight: 700;
    white-space: normal;
}
.badge.success { background: #dcfce7; color: #166534; }
.badge.warning { background: #fef3c7; color: #92400e; }
.professional-form { display: flex; flex-direction: column; gap: 18px; }
.form-section-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 24px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    min-width: 0;
}
.form-section-card h2 { margin: 0 0 16px; }
.protected-section { border-left: 5px solid #0f4c81; }
.section-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.royalty-table input { min-width: 110px; margin: 0; }
.sticky-actions {
    position: sticky;
    bottom: 0;
    background: rgba(244, 246, 248, .92);
    backdrop-filter: blur(6px);
    padding: 12px 0;
}
input:disabled, textarea:disabled, select:disabled {
    background: #f8fafc;
    color: #64748b;
    cursor: not-allowed;
}
@media print {
    .badge { border: 1px solid #ccc; background: #fff !important; color: #000 !important; }
    .form-section-card { box-shadow: none; page-break-inside: avoid; }
    input, textarea { border: 0; padding: 0; }
}

/* Users page: multi-role modal layout */
.users-table {
    width: 100%;
    min-width: 980px;
    table-layout: fixed;
}

.users-table th,
.users-table td {
    vertical-align: middle;
}

.users-table th:nth-child(1),
.users-table td:nth-child(1) { width: 15%; }
.users-table th:nth-child(2),
.users-table td:nth-child(2) { width: 20%; }
.users-table th:nth-child(3),
.users-table td:nth-child(3) { width: 14%; }
.users-table th:nth-child(4),
.users-table td:nth-child(4) { width: 22%; }
.users-table th:nth-child(5),
.users-table td:nth-child(5) { width: 13%; }
.users-table th:nth-child(6),
.users-table td:nth-child(6) { width: 16%; }

.inactive-row { opacity: 0.75; }

.users-save-btn {
    width: auto;
    min-width: 130px;
    margin-top: 0;
}

.danger-btn {
    background: #b91c1c;
    width: auto;
    min-width: 80px;
    margin-top: 0;
    padding: .45rem .7rem;
}

.danger-btn:hover { background: #991b1b; }

button:disabled, .btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, 0.55);
    padding: 24px;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.is-open { display: flex; }

.modal-card {
    width: min(720px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
    padding: 24px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 18px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 14px;
}

.modal-header h2 { margin: 0; }
.modal-header p { margin: 6px 0 0; color: #64748b; }

.modal-close {
    width: 40px;
    min-width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    border-radius: 999px;
    background: #e2e8f0;
    color: #0f172a;
    font-size: 26px;
    line-height: 1;
}

.modal-close:hover { background: #cbd5e1; }

.modal-role-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
}

.modal-role-option {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    font-weight: 700;
    cursor: pointer;
}

.modal-role-option:hover {
    border-color: #0f4c81;
    background: #eef6ff;
}

.modal-role-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    flex: 0 0 auto;
}

.modal-role-option span { line-height: 1.25; }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 22px;
    border-top: 1px solid #e2e8f0;
    padding-top: 16px;
}

@media (max-width: 640px) {
    .modal-card { padding: 18px; }
    .modal-actions .btn,
    .modal-actions button { width: 100%; }
}

/* Standard professional report table layout
   Use for: Monthly Figures, Royalties, Insurance Claims, Joinings, Funeral Services, Audit Logs */
.system-report-wrap,
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.system-report-table {
    width: 100%;
    min-width: 1200px;
    border-collapse: collapse;
    table-layout: auto;
    background: #fff;
}

.system-report-table th,
.system-report-table td {
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
    word-break: normal;
    overflow-wrap: normal;
    text-align: center;
    vertical-align: middle;
    font-size: 11px;
    line-height: 1.25;
    padding: 8px 10px;
    border-bottom: 1px solid #e2e8f0;
    max-width: none;
}

.system-report-table th {
    font-weight: 700;
    color: #1f2937;
    background: #f8fafc;
}

.system-report-table td:first-child,
.system-report-table th:first-child {
    text-align: left;
}

.monthly-figures-table,
.monthly-import-table,
.royalties-table,
.insurance-claims-table,
.joinings-table,
.funeral-services-table,
.audit-logs-table {
    min-width: 2200px;
}

.monthly-figures-table th:nth-child(1),
.monthly-figures-table td:nth-child(1),
.monthly-figures-table th:nth-child(2),
.monthly-figures-table td:nth-child(2) {
    min-width: 90px;
}

.monthly-figures-table th:nth-child(3),
.monthly-figures-table td:nth-child(3) {
    min-width: 150px;
}

.monthly-figures-table th:nth-child(n+4),
.monthly-figures-table td:nth-child(n+4) {
    min-width: 140px;
}

.system-report-table .button-row {
    justify-content: center;
    flex-wrap: nowrap;
}

.system-report-table .button-row form {
    display: inline-block;
    margin: 0;
}

.system-report-table .button-row button,
.system-report-table .button-row .btn {
    width: auto;
    min-width: 54px;
    padding: 0.42rem 0.65rem;
    margin: 0;
    font-size: 0.75rem;
}

.users-table {
    min-width: 980px;
}

.users-table th:nth-child(1),
.users-table td:nth-child(1) { width: 18%; }
.users-table th:nth-child(2),
.users-table td:nth-child(2) { width: 24%; }
.users-table th:nth-child(3),
.users-table td:nth-child(3) { width: 12%; }
.users-table th:nth-child(4),
.users-table td:nth-child(4) { width: 26%; }
.users-table th:nth-child(5),
.users-table td:nth-child(5) { width: 20%; text-align: center; }

.user-action-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.user-action-row form {
    margin: 0;
    display: inline-block;
}

.inactive-row { opacity: 0.75; }

.users-save-btn,
.active-btn,
.danger-btn {
    width: auto;
    min-width: 80px;
    margin-top: 0;
    padding: .45rem .7rem;
}

.active-btn { background: #15803d; }
.active-btn:hover { background: #166534; }
.danger-btn { background: #b91c1c; }
.danger-btn:hover { background: #991b1b; }

button:disabled, .btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, 0.55);
    padding: 24px;
    align-items: center;
    justify-content: center;
}

.modal-backdrop.is-open { display: flex; }

.modal-card {
    width: min(720px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    background: #fff;
    border-radius: 14px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
    padding: 24px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 18px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 14px;
}

.modal-header h2 { margin: 0; }
.modal-header p { margin: 6px 0 0; color: #64748b; }

.modal-close {
    width: 40px;
    min-width: 40px;
    height: 40px;
    margin: 0;
    padding: 0;
    border-radius: 999px;
    background: #e2e8f0;
    color: #0f172a;
    font-size: 22px;
    line-height: 1;
}

.modal-close:hover { background: #cbd5e1; }

.modal-role-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
}

.modal-role-option {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    background: #f8fafc;
    font-weight: 700;
    cursor: pointer;
}

.modal-role-option:hover {
    border-color: #0f4c81;
    background: #eef6ff;
}

.modal-role-option input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    flex: 0 0 auto;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 22px;
    border-top: 1px solid #e2e8f0;
    padding-top: 16px;
}

@media print {
    .system-report-table {
        min-width: 0;
        width: 100%;
        table-layout: auto;
    }

    .system-report-table th,
    .system-report-table td {
        font-size: 7.5pt;
        padding: 4px 5px;
        white-space: nowrap;
    }
}

@media (max-width: 640px) {
    .modal-card { padding: 18px; }
    .modal-actions .btn,
    .modal-actions button { width: 100%; }
}

.franchise-user-layout {
    display: grid;
    grid-template-columns: minmax(260px, 340px) 1fr;
    gap: 20px;
    align-items: start;
}

.franchise-list-card,
.franchise-users-card {
    background: #fff;
    border-radius: 14px;
    padding: 18px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.franchise-list-card h2 {
    margin-top: 0;
}

.franchise-list-item {
    display: block;
    padding: 12px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    margin-bottom: 10px;
    color: #0f172a;
    text-decoration: none;
    background: #f8fafc;
}

.franchise-list-item:hover,
.franchise-list-item.active {
    border-color: #0f4c81;
    background: #eef6ff;
}

.franchise-list-item span {
    display: block;
    color: #64748b;
    font-size: 0.82rem;
    margin-top: 4px;
}

@media (max-width: 900px) {
    .franchise-user-layout {
        grid-template-columns: 1fr;
    }
}

.branch-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
    margin-bottom: 22px;
}

.branch-card {
    display: block;
    padding: 20px;
    border-radius: 16px;
    background: #fff;
    border: 1px solid #e2e8f0;
    text-decoration: none;
    color: #0f172a;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

.branch-card:hover,
.branch-card.active {
    border-color: #0f4c81;
    background: #eef6ff;
}

.branch-card h2 {
    margin: 0 0 8px;
}

.branch-card p {
    color: #64748b;
    min-height: 38px;
}

.branch-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: #475569;
}

.branch-switcher {
    display: flex;
    align-items: center;
    gap: 8px;
}

.branch-switcher select {
    min-width: 240px;
    padding: 8px 10px;
}

.branch-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px 18px;
    margin: 16px 0;
}

.branch-details div {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.branch-details span {
    color: #64748b;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.branch-details strong {
    color: #0f172a;
    font-size: 0.95rem;
}

.royalty-dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.metric-card {
    background: #fff;
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    padding: 16px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

.metric-card span {
    display: block;
    color: #64748b;
    font-size: 0.82rem;
    margin-bottom: 8px;
}

.metric-card strong {
    display: block;
    color: #0f172a;
    font-size: 1.35rem;
}

.inline-payment-form {
    display: grid;
    grid-template-columns: 110px 140px minmax(160px, 1fr) auto;
    gap: 6px;
    margin-top: 8px;
    min-width: 520px;
}

.inline-payment-form input {
    padding: 6px 8px;
    font-size: 0.82rem;
}

@media (max-width: 900px) {
    .inline-payment-form {
        grid-template-columns: 1fr;
        min-width: 0;
    }
}


.selected-franchise-label {
    display: block;
    color: #64748b;
    font-size: 0.78rem;
    margin-top: 2px;
}

.secondary-link {
    background: #eef2f7 !important;
    color: #1f3f6d !important;
}

.dashboard-action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-top: 18px;
}

.dashboard-action-card {
    display: block;
    background: #fff;
    border: 1px solid #dbe7f3;
    border-radius: 14px;
    padding: 18px;
    text-decoration: none;
    color: #0f172a;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.dashboard-action-card strong {
    display: block;
    font-size: 1.05rem;
    margin-bottom: 6px;
}

.dashboard-action-card span {
    color: #64748b;
}

.franchise-dashboard-card {
    margin-bottom: 16px;
}


.locked-section {
    border-left: 6px solid #94a3b8;
    background: #f8fafc;
}

.locked-section input:disabled,
.locked-section select:disabled {
    background: #eef2f7;
    color: #64748b;
    cursor: not-allowed;
}

.activity-summary-card {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    margin-bottom: 18px;
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    background: #ffffff;
}

.dashboard-franchise-heading {
    margin: 20px 0 12px;
    font-size: 1.15rem;
}

.branch-status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    display: inline-block;
}

.status-dot.green { background: #16a34a; }
.status-dot.red { background: #dc2626; }

.branch-card-active {
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.branch-card-inactive {
    border-color: #fecaca;
    background: #fff1f2;
}

.branch-card-active:hover {
    border-color: #16a34a;
    background: #dcfce7;
}

.branch-card-inactive:hover {
    border-color: #dc2626;
    background: #ffe4e6;
}
.badge.danger { background: #fee2e2; color: #991b1b; }

.branch-context-card {
  background: #fff;
  border: 1px solid #dfe7f1;
  border-radius: 16px;
  padding: 18px 22px;
  margin: 18px 0;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
}
.branch-context-card h2 {
  margin: 0 0 8px;
}
.branch-selector-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.branch-selector-row select {
  min-width: 280px;
  max-width: 520px;
  padding: 10px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
}

/* V3.5: drag-to-scroll support for wide data tables */
.table-responsive,
.system-report-wrap {
    overflow: auto;
    max-width: 100%;
    cursor: grab;
    user-select: auto;
    scrollbar-width: thin;
}

.table-responsive.is-dragging,
.system-report-wrap.is-dragging {
    cursor: grabbing;
    user-select: none;
}

.table-responsive table,
.system-report-wrap table {
    min-width: max-content;
}

.scroll-hint {
    font-size: 0.85rem;
    color: #64748b;
    margin: 6px 0 10px;
}

/* V3.9: period filter beside branch selector */
.branch-selector-row,
.period-filter-form {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.period-filter-form {
    margin: 0;
}
.period-filter-form select {
    min-width: 120px;
}
@media (max-width: 800px) {
    .branch-selector-row,
    .period-filter-form {
        align-items: stretch;
        flex-direction: column;
    }
}

/* Linked franchise grouped cards */
.linked-branch-card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}
.linked-branch-card {
  margin-bottom: 1rem;
}
.compact-header {
  margin-bottom: 0.75rem;
}

/* Heat map module */
.heatmap-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.heatmap-layout {
    display: grid;
    grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}
.heatmap-controls input,
.heatmap-controls select {
    margin-bottom: 10px;
}
.heatmap-controls hr {
    border: 0;
    border-top: 1px solid #e2e8f0;
    margin: 18px 0;
}
.heatmap-button-row .btn {
    min-width: 80px;
}
.heatmap-main {
    min-width: 0;
}
.heatmap-map-card {
    padding: 0;
    overflow: hidden;
}
#heatMap {
    width: 100%;
    height: 620px;
    min-height: 520px;
}
.heatmap-record-table {
    min-width: 1250px;
}
.warning-row td {
    background: #fff7ed;
}
.heatmap-popup {
    max-width: 300px;
    font-size: 13px;
    line-height: 1.45;
}
@media (max-width: 1000px) {
    .heatmap-layout {
        grid-template-columns: 1fr;
    }
    #heatMap {
        height: 520px;
    }
}


/* Attendance module */
.attendance-tabs .btn { margin-top: 0; }
.attendance-id-card {
    width: 360px;
    max-width: 100%;
    background: #fff;
    border: 1px solid #dbe7f3;
    border-radius: 18px;
    padding: 26px;
    text-align: center;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.10);
}
.attendance-id-card .id-card-logo {
    font-weight: 800;
    color: #0f4c81;
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-bottom: 18px;
}
@media print {
    .attendance-tabs, .topbar, .sidebar, .form-actions, button { display: none !important; }
    .attendance-id-card { box-shadow: none; border: 1px solid #000; margin: 0 auto; }
}

/* FINAL SIDEBAR LAYOUT - single source of truth */
:root {
    --sidebar-width: 280px;
}

html {
    overflow-y: scroll;
    scrollbar-gutter: stable;
}

body.app-body {
    margin: 0;
    min-height: 100vh;
    background: #f4f6f8;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    width: 100%;
}

.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    height: 100vh;
    max-height: 100vh;
    background: #0f172a;
    color: white;
    padding: 22px 18px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1000;
    scrollbar-gutter: stable both-edges;
    contain: layout paint style;
    transform: translateZ(0);
}

.sidebar,
.sidebar * {
    transition: none;
    animation: none;
}

.sidebar-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    min-height: 150px;
    padding-bottom: 24px;
    margin-bottom: 18px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    color: white;
    text-align: center;
    text-decoration: none;
}

.sidebar-logo img {
    display: block;
    width: 180px;
    height: 81px;
    max-width: 180px;
    object-fit: contain;
    border-radius: 12px;
}

.sidebar-logo span {
    display: block;
    color: white;
    font-weight: 800;
    font-size: 1.45rem;
    line-height: 1.25;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 24px;
}

.sidebar-nav a {
    color: #cbd5e1;
    padding: 13px 14px;
    border-radius: 10px;
    font-weight: 600;
    white-space: normal;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: #0f4c81;
    color: white;
}

.main-panel {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
}

@media (max-width: 820px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: relative;
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        height: auto;
    }

    .sidebar-nav {
        flex-direction: row;
        overflow-x: auto;
    }

    .sidebar-nav a {
        white-space: nowrap;
    }

    .main-panel {
        margin-left: 0;
        width: 100%;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
        padding: 16px 18px;
    }

    .topbar-user {
        flex-wrap: wrap;
    }

    .content-area {
        padding: 18px;
    }
}

/* Users page linked-franchise details - moved from template so styles stay in one place */
.user-name-link {
  color: #0b2a4a;
  text-decoration: none;
}
.user-name-link:hover {
  text-decoration: underline;
}
.locked-role-box {
  background: #f8fafc;
  border: 1px solid #d9e2ec;
  border-radius: 10px;
  padding: 1rem;
}
.user-linked-summary {
  margin-top: 0.35rem;
  color: #5f738a;
  font-size: 0.85rem;
}
.linked-groups-card {
  margin-top: 1rem;
}
.linked-group-list {
  display: grid;
  gap: 0.75rem;
}
.linked-group-item, .current-linked-box {
  background: #f8fafc;
  border: 1px solid #d9e2ec;
  border-radius: 10px;
  padding: 0.85rem;
}
.linked-branches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.linked-branch-pill {
  background: #e8f1fb;
  border: 1px solid #c8d9ec;
  border-radius: 999px;
  padding: 0.25rem 0.6rem;
  font-size: 0.82rem;
}
