body {
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: #f4f7fb;
    color: #1c2b3f;
}

.layout {
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 240px;
    background: linear-gradient(180deg, #14243a 0%, #0d192a 100%);
    color: #fff;
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    box-sizing: border-box;
    box-shadow: 4px 0 18px rgba(16, 31, 51, 0.12);
}

.sidebar-month-summary {
    margin-top: 14px;
    flex: 0 0 auto;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.07);
    font-size: 12px;
}

.emi-details-toggle > summary {
    cursor: pointer;
    list-style: none;
    padding: 12px 14px;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    background: #fff;
}

.emi-details-toggle > summary::-webkit-details-marker {
    display: none;
}

.emi-details-toggle > summary::after {
    content: 'Show';
    color: #495057;
    font-size: 12px;
    font-weight: 600;
}

.emi-details-toggle[open] > summary {
    margin-bottom: 12px;
    border-color: #adb5bd;
}

.emi-details-toggle[open] > summary::after {
    content: 'Hide';
}

.sidebar-summary-line,
.sidebar-summary-total {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-top: 5px;
}

.sidebar-summary-total {
    margin-top: 9px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    font-size: 13px;
}

.sidebar h1 {
    margin: 0;
    font-size: 20px;
    text-align: center;
}

.brand-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.brand-logo {
    width: 90px;
    height: 90px;
    border-radius: 12px;
    object-fit: cover;
    background: #fff;
    padding: 4px;
}

.sidebar nav {
    margin-top: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar nav a {
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    padding: 9px 11px;
    border: 1px solid rgba(255, 255, 255, 0.11);
    border-radius: 9px;
    display: block;
    transition: background-color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.sidebar nav a:hover {
    background: rgba(80, 145, 224, 0.22);
    color: #fff;
    border-color: rgba(135, 184, 240, 0.42);
    transform: translateX(2px);
}

.container {
    flex: 1;
    max-width: none;
    margin: 0;
    min-width: 0;
    background: transparent;
    padding: 24px;
    box-sizing: border-box;
}

h2, h3, h4 {
    color: #182a42;
    letter-spacing: -0.02em;
}

h2 {
    font-weight: 700;
}

.text-muted {
    color: #6b788a !important;
}

.item-form-card {
    border-radius: 10px;
}

.login-logo-wrap {
    text-align: center;
    margin-bottom: 8px;
}

.login-logo {
    width: 80px;
    height: 80px;
    border: 1px solid #000;
    border-radius: 10px;
    object-fit: cover;
    background: #fff;
    padding: 4px;
}

.login-center {
    max-width: 420px;
    margin: 40px auto;
}

.login-center h2,
.login-center p {
    text-align: center;
}

h2 {
    margin-top: 0;
    color: #000;
}

form {
    margin-bottom: 24px;
}

label {
    display: block;
    margin-top: 10px;
    font-weight: bold;
}

input, textarea, select {
    width: 100%;
    padding: 9px 11px;
    margin-top: 6px;
    box-sizing: border-box;
    border: 1px solid #cfd8e4;
    border-radius: 8px;
    background: #fff;
    color: #1c2b3f;
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

input:focus, textarea:focus, select:focus {
    border-color: #6da5e8;
    outline: 0;
    box-shadow: 0 0 0 3px rgba(54, 126, 210, 0.14);
}

button {
    margin-top: 12px;
    background: #1d4f86;
    color: #fff;
    border: 1px solid #1d4f86;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
}

button:hover {
    background: #173e6b;
    border-color: #173e6b;
    color: #fff;
}

.btn {
    border-radius: 8px;
    font-weight: 600;
}

.btn:focus-visible,
.sidebar nav a:focus-visible {
    outline: 3px solid rgba(55, 130, 215, 0.34);
    outline-offset: 2px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
}

th, td {
    border: 1px solid #ddd;
    padding: 10px;
    text-align: left;
}

th {
    background: #203954;
    color: #fff;
}

.dataTables_wrapper {
    margin-top: 12px;
}

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter {
    margin-bottom: 12px;
}

.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
    width: auto;
    min-width: 90px;
    margin-left: 6px;
    padding: 6px 8px;
    border-radius: 0.375rem;
    border: 1px solid #ced4da;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    margin-top: 12px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    border: 1px solid #d5deea !important;
    background: #fff !important;
    color: #294563 !important;
    padding: 4px 10px !important;
    margin-left: 4px;
    border-radius: 8px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
    opacity: 0.55;
    cursor: default !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    background: #1d4f86 !important;
    border-color: #1d4f86 !important;
    color: #fff !important;
}

.dataTables_wrapper .dataTables_paginate span .paginate_button {
    margin-left: 4px !important;
}

div.dataTables_wrapper div.dataTables_paginate ul.pagination .page-item.active .page-link,
div.dataTables_wrapper div.dataTables_paginate ul.pagination .page-item .page-link:hover,
div.dataTables_wrapper div.dataTables_paginate ul.pagination .page-item .page-link:focus {
    background: #1d4f86 !important;
    border-color: #1d4f86 !important;
    color: #fff !important;
    box-shadow: none !important;
}

div.dataTables_wrapper div.dataTables_paginate ul.pagination .page-link {
    color: #294563 !important;
    border-radius: 7px;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.card {
    border-radius: 12px;
    background: #fff;
    border: 1px solid #e0e7ef;
    box-shadow: 0 3px 12px rgba(28, 48, 74, 0.055);
}

.card-body {
    padding: 18px;
}

.table-hover > tbody > tr:hover > * {
    --bs-table-bg-state: #eef5fc;
}

.table {
    --bs-table-border-color: #e0e6ed;
}

.table thead th {
    white-space: nowrap;
}

.table-striped > tbody > tr:nth-of-type(odd) > * {
    --bs-table-bg-type: #f8fafd;
}

.cards .card {
    padding: 14px;
}

.card .title {
    font-size: 13px;
    color: #000;
}

.card .value {
    font-size: 24px;
    margin-top: 6px;
    font-weight: bold;
}

.error {
    color: #8f2630;
    font-weight: bold;
    border: 1px solid #f0c6c8;
    border-radius: 8px;
    padding: 10px 12px;
    background: #fff3f3;
}

.flash-message {
    padding: 11px 14px;
    border: 1px solid #d9e2ed;
    border-radius: 9px;
    background: #fff;
    font-weight: 600;
}

.flash-success {
    border-color: #b9dfc3;
    background: #effaf2;
}

.flash-warning {
    border-color: #f0d79b;
    background: #fff9e9;
}

.payment-qr-card {
    border: 1px solid #000;
    background: #fff;
    padding: 12px;
}

.payment-qr-card img {
    width: 100%;
    max-width: 280px;
    height: auto;
    border: 1px solid #000;
    background: #fff;
}

.narrow-form {
    max-width: 420px;
}

.inline-form {
    display: grid;
    grid-template-columns: 1fr 120px 140px auto;
    gap: 6px;
    margin: 0;
}

.sale-item-row {
    grid-template-columns: 1fr 120px 140px auto;
    margin-top: 6px;
}

a {
    color: #000;
}

/* Purchase payment: native <dialog> + fallback overlay */
.payment-dialog {
    border: none;
    padding: 0;
    margin: auto;
    max-width: 520px;
    width: calc(100vw - 32px);
    max-height: 90vh;
    overflow: visible;
    background: transparent;
}

.payment-dialog::backdrop {
    background: rgba(0, 0, 0, 0.45);
}

.payment-dialog-fallback {
    position: fixed;
    inset: 0;
    z-index: 2147483647;
    width: 100vw;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    border: none;
    padding: 16px;
    box-sizing: border-box;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

.modal-panel {
    background: #fff;
    border: 2px solid #000;
    max-width: 520px;
    width: 100%;
    max-height: min(90vh, 100%);
    overflow: auto;
    padding: 0;
    box-sizing: border-box;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #000;
}

.modal-header h3 {
    margin: 0;
    font-size: 18px;
}

.modal-close {
    margin: 0;
    padding: 4px 10px;
    font-size: 22px;
    line-height: 1;
    background: #fff;
    color: #000;
}

.modal-body {
    padding: 16px;
}

.payment-modal-summary p {
    margin: 0 0 12px;
}

.payment-history-table {
    width: 100%;
    font-size: 13px;
    margin-top: 8px;
}

.payment-history-table th,
.payment-history-table td {
    padding: 6px;
}

.payment-modal-open {
    margin-top: 8px;
    display: inline-block;
}

.payment-status-badge {
    display: inline-block;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: bold;
    border: 1px solid #000;
}

.payment-status-pending {
    background: #e9ecef;
    color: #000;
}

.payment-status-partial {
    background: #eee;
    color: #000;
}

.payment-status-paid {
    background: #d1e7dd;
    color: #000;
}

.stock-low {
    background: #f8d7da !important;
    color: #842029;
    font-weight: bold;
}

.stock-zero {
    background: #f1aeb5 !important;
    color: #58151c;
    font-weight: bold;
}

.site-footer {
    padding: 12px 16px 20px;
    text-align: center;
    font-size: 14px;
}

.site-footer a {
    text-decoration: none;
    font-weight: 600;
}

.site-footer a:hover,
.site-footer a:focus {
    text-decoration: underline;
}

@media (max-width: 991.98px) {
    body {
        font-size: 15px;
        overflow-x: hidden;
    }

    .layout {
        min-height: 100vh;
        display: block;
    }

    .sidebar {
        position: sticky;
        top: 0;
        z-index: 1030;
        width: 100%;
        min-height: 0;
        padding: 10px 12px;
        border-bottom: 1px solid #222;
    }

    .brand-block {
        flex-direction: row;
        justify-content: center;
        gap: 8px;
    }

    .brand-logo {
        width: 44px;
        height: 44px;
        border-radius: 8px;
    }

    .sidebar h1 {
        font-size: 16px;
        text-align: left;
    }

    .sidebar nav {
        margin-top: 10px;
        flex-direction: row;
        gap: 8px;
        overflow-x: auto;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }

    .sidebar nav a {
        flex: 0 0 auto;
        padding: 8px 10px;
        white-space: nowrap;
    }

    .container {
        width: 100%;
        padding: 14px 12px 20px;
    }

    h2 {
        font-size: 22px;
    }

    .cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        margin-top: 12px;
    }

    .cards .card {
        padding: 12px;
    }

    .card .title {
        font-size: 12px;
        line-height: 1.25;
    }

    .card .value {
        font-size: 19px;
        line-height: 1.2;
        word-break: break-word;
    }

    .card-body {
        padding: 14px;
    }

    .row {
        --bs-gutter-x: 0.75rem;
        --bs-gutter-y: 0.75rem;
    }

    input,
    textarea,
    select,
    button,
    .btn {
        min-height: 42px;
        font-size: 15px;
    }

    .d-flex.gap-2 {
        gap: 8px !important;
    }

    .inline-form,
    .sale-item-row {
        grid-template-columns: 1fr;
    }

    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        margin-top: 8px;
    }

    .table-responsive table,
    .dataTable {
        min-width: 720px;
    }

    th,
    td {
        padding: 8px;
        white-space: nowrap;
    }

    td {
        vertical-align: middle;
    }

    .dataTables_wrapper {
        margin-top: 8px;
    }

    .dataTables_wrapper .row {
        row-gap: 8px;
    }

    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter,
    div.dataTables_wrapper div.dataTables_length,
    div.dataTables_wrapper div.dataTables_filter,
    div.dataTables_wrapper div.dataTables_info,
    div.dataTables_wrapper div.dataTables_paginate {
        text-align: left;
        width: 100%;
    }

    .dataTables_wrapper .dataTables_filter label,
    .dataTables_wrapper .dataTables_length label {
        width: 100%;
    }

    .dataTables_wrapper .dataTables_filter input,
    .dataTables_wrapper .dataTables_length select {
        width: 100%;
        margin: 6px 0 0;
    }

    div.dataTables_wrapper div.dataTables_paginate ul.pagination {
        justify-content: flex-start !important;
        flex-wrap: wrap;
        gap: 4px;
    }

    .payment-dialog {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
    }

    .payment-dialog-fallback {
        padding: 8px;
        align-items: flex-start;
    }

    .modal-panel {
        max-height: calc(100vh - 16px);
    }

    .modal-body {
        padding: 12px;
    }

    .payment-modal-summary p {
        line-height: 1.7;
    }

    .payment-history-table {
        min-width: 560px;
    }
}

@media (max-width: 575.98px) {
    .container {
        padding: 12px 8px 18px;
    }

    .cards {
        grid-template-columns: 1fr;
    }

    .card-body {
        padding: 12px;
    }

    .login-center {
        margin: 20px auto;
    }

    .table-responsive table,
    .dataTable {
        min-width: 640px;
    }

    .btn,
    button {
        width: 100%;
    }

    .payment-modal-open,
    .modal-close,
    div.dataTables_wrapper div.dataTables_paginate .page-link {
        width: auto;
    }

    .d-flex.flex-wrap .btn,
    .d-flex.flex-wrap button,
    .d-flex.gap-2 .btn,
    .d-flex.gap-2 button {
        flex: 1 1 140px;
    }
}
