:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #64748b;
    --secondary-hover: #475569;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --success-hover: #059669;
    --bg-main: #f8fafc;
    --surface: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg-main);
    color: var(--text-main);
    font-family: 'Cairo', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.topbar {
    min-height: 70px;
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(226, 232, 240, 0.6);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    overflow: visible;
}

.topbar .navbar-brand {
    display: flex;
    flex-direction: column;
}

.topbar strong {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1.2;
}

.topbar span {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
}

.topbar nav {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: center;
}

.header-search {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1 1 320px;
    max-width: 460px;
    margin-inline: auto;
}

.header-search input {
    min-height: 36px;
    padding: 8px 12px;
    width: 100%;
    min-width: 240px;
}

.header-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 200;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    max-height: 280px;
    overflow-y: auto;
}

.header-search-result {
    display: block;
    width: 100%;
    padding: 7px 10px;
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    line-height: 1.25;
}

.header-search-result:last-child {
    border-bottom: 0;
}

.header-search-result:hover,
.header-search-result.is-active {
    background: rgba(79, 70, 229, 0.08);
    text-decoration: none;
}

.header-search-result small {
    display: block;
    color: var(--text-muted);
    margin-top: 1px;
    font-size: 11px;
}

.nav-link {
    color: var(--text-main) !important;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.nav-link:hover {
    color: var(--primary) !important;
    background: rgba(79, 70, 229, 0.08);
    text-decoration: none;
}

.user-menu .dropdown-toggle {
    color: var(--text-main) !important;
    font-weight: 700;
    text-decoration: none;
}

.user-menu .dropdown-menu {
    border-color: var(--border);
    box-shadow: var(--shadow-lg);
}

.user-menu form {
    margin: 0;
}

.access-section + .access-section {
    margin-top: 36px;
    padding-top: 28px;
    border-top: 1px solid var(--border);
}

.access-section h3 {
    margin-top: 0;
    margin-bottom: 18px;
}

.access-section form > .actions,
.access-section form > button[type="submit"] {
    margin-top: 18px;
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: var(--transition);
}

a:hover {
    text-decoration: underline;
    color: var(--primary-hover);
}

.link-button {
    min-height: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--primary);
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
}
h2{
margin-top: 0.5em!important;
}

.link-button:hover {
    background: transparent;
    text-decoration: underline;
    color: var(--primary-hover);
}

.page {
    max-width: 95%;
    margin: 0 auto;
    padding: 32px 28px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.panel:hover {
    box-shadow: var(--shadow-md);
}

.grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 3em;
}

.metric {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.metric::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
    opacity: 0.8;
}

.metric:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.metric span {
    display: block;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metric strong {
    font-size: 28px;
    color: var(--text-main);
    font-weight: 700;
}

.dashboard-highlight-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.dashboard-highlight-row .metric {
    border-color: rgba(79, 70, 229, 0.25);
    background: linear-gradient(135deg, #ffffff 0%, #eef2ff 100%);
}

.dashboard-highlight-row .metric strong {
    font-size: 32px;
}

.dashboard-highlight-row-secondary .metric {
    border-color: rgba(16, 185, 129, 0.25);
    background: linear-gradient(135deg, #ffffff 0%, #ecfdf5 100%);
}

.dashboard-highlight-row-secondary .metric::after {
    background: var(--success);
}

.dashboard-split {
    display: grid;
    grid-template-columns: minmax(420px, 1.25fr) minmax(300px, 0.75fr);
    gap: 20px;
    align-items: start;
}

.dashboard-chart-panel h2 {
    margin-top: 0;
}

.dashboard-chart-stack {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
    align-items: start;
}

.dashboard-chart-block h2 {
    margin-top: 0;
    text-align: center;
}

.dashboard-chart-block {
    display: grid;
    justify-items: center;
    gap: 16px;
}

.dashboard-pie {
    width: min(100%, 260px);
    aspect-ratio: 1;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    isolation: isolate;
    --slice-hit-size: 58%;
}

.dashboard-pie-grand {
    background:
        conic-gradient(
            #4f46e5 0 var(--opening),
            #10b981 var(--opening) calc(var(--opening) + var(--current)),
            #f59e0b calc(var(--opening) + var(--current)) 100%
        );
    box-shadow: inset 0 0 0 18px #fff, var(--shadow-md);
}

.dashboard-pie-payment {
    background:
        conic-gradient(
            #0ea5e9 0 var(--paid),
            #ef4444 var(--paid) 100%
        );
    box-shadow: inset 0 0 0 18px #fff, var(--shadow-md);
}

.pie-hit {
    position: absolute;
    width: var(--slice-hit-size);
    height: var(--slice-hit-size);
    border-radius: 999px;
    z-index: 2;
}

.pie-hit-opening,
.pie-hit-paid {
    top: 0;
    right: 0;
}

.pie-hit-current {
    bottom: 0;
    right: 0;
}

.pie-hit-discount,
.pie-hit-remaining {
    bottom: 0;
    left: 0;
}

.dashboard-legend {
    display: grid;
    gap: 8px;
    color: var(--text-main);
    font-weight: 600;
    width: 100%;
}

.legend-swatch {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-inline-end: 8px;
}

.legend-swatch.opening {
    background: #4f46e5;
}

.legend-swatch.current {
    background: #10b981;
}

.legend-swatch.discount {
    background: #f59e0b;
}

.legend-swatch.total-after-discount {
    background: #a855f7;
}

.legend-swatch.paid {
    background: #0ea5e9;
}

.legend-swatch.remaining {
    background: #ef4444;
}

.dashboard-supporting-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dashboard-totals-panel {
    gap: 12px;
}

.dashboard-totals-panel .metric {
    padding: 14px 16px;
}

.dashboard-totals-panel .metric span {
    font-size: 12px;
    margin-bottom: 4px;
}

.dashboard-totals-panel .metric strong {
    font-size: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 700;
    color: var(--text-main);
}

input,
select,
textarea,
button {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    transition: var(--transition);
    color: var(--text-main);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

input[type="checkbox"], input[type="radio"] {
    width: auto;
    accent-color: var(--primary);
    transform: scale(1.1);
}

.form-row {
    display: grid;
    grid-template-columns: minmax(130px, 180px) minmax(0, 1fr);
    gap: 12px 16px;
    align-items: center;
    margin-bottom: 18px;
}

.form-row > label {
    margin-bottom: 0;
}

.form-row > textarea {
    align-self: stretch;
}

.form-row > .muted,
.form-row > .actions {
    grid-column: 2;
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 10px 20px;
    border: 0;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-hover) 100%);
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.button.secondary,
button.secondary {
    background: var(--surface);
    color: var(--text-main);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.button.danger,
button.danger {
    background: linear-gradient(135deg, var(--danger) 0%, var(--danger-hover) 100%);
}

button:hover,
.button:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    text-decoration: none;
    color: #fff;
}

.button.secondary:hover,
button.secondary:hover {
    background: var(--bg-main);
    color: var(--text-main);
}

.button.danger:hover,
button.danger:hover {
    background: linear-gradient(135deg, var(--danger-hover) 0%, #b91c1c 100%);
}

.inline-form {
    display: inline;
}

.error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.warning {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
}

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

.payment-options-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

.payment-options-table {
    min-width: 0;
}

.report-heading {
    justify-content: space-between;
    margin-bottom: 16px;
}

.report-summary .metric strong {
    font-size: 20px;
    line-height: 1.3;
}

.muted {
    color: var(--text-muted);
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

th,
td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    text-align: right;
    transition: var(--transition);
}

th {
    color: var(--secondary);
    background: var(--bg-main);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 0.5px;
}

th:first-child {
    border-top-right-radius: var(--radius-md);
}

th:last-child {
    border-top-left-radius: var(--radius-md);
}

tbody tr {
    transition: var(--transition);
}

tbody tr:hover {
    background-color: rgba(248, 250, 252, 0.8);
}

.selected-row td {
    background: rgba(16, 185, 129, 0.05);
}

@media (max-width: 850px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        padding: 16px 20px;
    }

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

    .dashboard-highlight-row,
    .dashboard-split,
    .dashboard-chart-stack,
    .dashboard-supporting-grid {
        grid-template-columns: 1fr;
    }

    .dashboard-pie {
        max-width: 260px;
        margin: 0 auto;
    }

    .two-col {
        grid-template-columns: 1fr;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .form-row > .muted,
    .form-row > .actions {
        grid-column: auto;
    }

    table {
        border-collapse: separate;
        border-spacing: 0 16px;
    }

    thead {
        display: none;
    }

    tbody,
    tfoot,
    tr,
    td,
    th {
        display: block;
        width: 100%;
    }

    tbody tr,
    tfoot tr {
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        background: var(--surface);
        overflow: hidden;
        box-shadow: var(--shadow-sm);
        margin-bottom: 16px;
    }

    td,
    th {
        border-bottom: 1px solid var(--border);
        text-align: right;
        padding: 12px 16px;
    }

    tbody td[data-label],
    tfoot td[data-label],
    tfoot th[data-label] {
        display: grid;
        grid-template-columns: minmax(110px, 38%) 1fr;
        gap: 12px;
        align-items: center;
    }

    tbody td[data-label]::before,
    tfoot td[data-label]::before,
    tfoot th[data-label]::before {
        content: attr(data-label);
        color: var(--text-muted);
        font-weight: 700;
        text-align: right;
    }

    tbody td:not([data-label]),
    tfoot td:not([data-label]),
    tfoot th:not([data-label]) {
        text-align: center;
    }

    td:last-child,
    th:last-child {
        border-bottom: 0;
    }

    td.actions,
    th.actions {
        display: flex;
        justify-content: center;
        gap: 8px;
    }
}

@media print {
    .topbar,
    .report-controls,
    .report-summary,
    .button,
    button {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .page {
        max-width: 100%;
        padding: 0;
    }

    .panel {
        border: 0;
        box-shadow: none;
        padding: 0;
    }
}
