:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-soft: #eef4f1;
    --text: #1d2527;
    --muted: #647174;
    --line: #dfe5e3;
    --primary: #146c5f;
    --primary-dark: #0d5147;
    --accent: #b7791f;
    --danger: #b42318;
    --success: #12805c;
    --warning: #a15c07;
    --radius: 8px;
    --shadow: 0 10px 30px rgba(20, 32, 35, .08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    letter-spacing: 0;
}

body.dark {
    --bg: #121615;
    --panel: #1b211f;
    --panel-soft: #222b28;
    --text: #eef4f1;
    --muted: #aebbb7;
    --line: #33403c;
    --primary: #34a58f;
    --primary-dark: #248271;
    --shadow: none;
}

a {
    color: inherit;
    text-decoration: none;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 245px;
    background: #10211f;
    color: #f7fbfa;
    padding: 18px 14px;
    overflow-y: auto;
}

.brand {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 22px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    font-weight: 800;
}

.brand-logo {
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 8px;
    background: #fff;
    border: 1px solid rgba(255, 255, 255, .25);
}

.brand small,
.muted {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.sidebar .brand small {
    color: #b8c7c2;
}

.sidebar nav {
    display: grid;
    gap: 4px;
}

.sidebar a {
    padding: 11px 12px;
    border-radius: 8px;
    color: #dce7e4;
}

.sidebar a.active,
.sidebar a:hover {
    background: rgba(255, 255, 255, .12);
    color: #fff;
}

.main {
    margin-left: 245px;
    padding: 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}

.topbar h1 {
    margin: 0 0 4px;
    font-size: 25px;
}

.topbar p {
    margin: 0;
    color: var(--muted);
}

.top-actions,
.actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.language-form select {
    min-height: 38px;
    width: auto;
    min-width: 110px;
}

.grid {
    display: grid;
    gap: 14px;
}

.grid.stats {
    grid-template-columns: repeat(5, minmax(150px, 1fr));
}

.grid.two {
    grid-template-columns: 1.2fr .8fr;
}

.grid.three {
    grid-template-columns: repeat(3, 1fr);
}

.card,
.stat,
.table-wrap,
.form-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card,
.form-panel {
    padding: 16px;
}

.stat {
    padding: 16px;
    min-height: 100px;
}

.stat span {
    color: var(--muted);
}

.stat strong {
    display: block;
    margin-top: 8px;
    font-size: 25px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

tr:last-child td {
    border-bottom: 0;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 10px;
    background: var(--panel);
    color: var(--text);
    font: inherit;
}

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

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
    cursor: pointer;
    font-weight: 700;
}

.button.primary,
button.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

.button.ghost {
    background: transparent;
}

.button.danger {
    border-color: var(--danger);
    color: var(--danger);
}

.icon-button {
    width: 38px;
    padding: 0;
}

.user-pill,
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 9px;
    border-radius: 999px;
    background: var(--panel-soft);
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
}

.badge.active,
.badge.completed,
.badge.success {
    background: rgba(18, 128, 92, .14);
    color: var(--success);
}

.badge.arrears,
.badge.danger {
    background: rgba(180, 35, 24, .14);
    color: var(--danger);
}

.badge.renewed,
.badge.warning {
    background: rgba(161, 92, 7, .14);
    color: var(--warning);
}

.alert {
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--panel-soft);
}

.alert.success {
    color: var(--success);
}

.alert.danger {
    color: var(--danger);
}

.login-screen {
    display: grid;
    place-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #f6f7f9, #e8f1ee);
}

.login-card {
    width: min(420px, 100%);
    display: grid;
    gap: 14px;
    padding: 24px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.login-card h1 {
    margin: 0;
}

.loan-calc {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 12px;
    background: var(--panel-soft);
    border-radius: 8px;
}

.receipt {
    max-width: 760px;
    margin: 0 auto;
    background: var(--panel);
    padding: 28px;
    border: 1px solid var(--line);
}

.bar-chart {
    display: grid;
    gap: 10px;
}

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

.bar-track {
    height: 14px;
    border-radius: 999px;
    background: var(--panel-soft);
    overflow: hidden;
}

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

.customer-photo {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
}

.profile-photo {
    width: min(220px, 100%);
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
}

/* Sidebar helper wrappers & close buttons for desktop */
.sidebar-overlay {
    display: none;
}
.sidebar-close {
    display: none;
}
.menu-toggle {
    display: none;
}
.topbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

@media (max-width: 1100px) {
    .grid.stats,
    .grid.three,
    .grid.two,
    .form-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 780px) {
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: 245px;
        z-index: 1001;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.45);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 1000;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.open {
        display: block;
        opacity: 1;
    }

    .sidebar-close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        color: #fff;
        font-size: 28px;
        cursor: pointer;
        padding: 0;
        margin-left: auto;
        min-height: auto;
        width: 32px;
        height: 32px;
    }

    .menu-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        background: var(--panel);
        color: var(--text);
        border: 1px solid var(--line);
        border-radius: 8px;
        width: 38px;
        height: 38px;
        cursor: pointer;
        transition: background-color 0.15s;
    }

    .menu-toggle:hover {
        background: var(--panel-soft);
    }

    .main {
        margin-left: 0;
        padding: 16px;
    }

    .topbar {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .top-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .grid.stats,
    .grid.three,
    .grid.two,
    .form-grid,
    .loan-calc {
        grid-template-columns: 1fr;
        align-items: stretch;
    }
}

/* ── Modal System ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, .45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    transition: opacity .25s ease;
}

.modal-overlay.open {
    display: flex;
    opacity: 1;
}

.modal {
    width: min(680px, 100%);
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 24px 64px rgba(0, 0, 0, .18);
    transform: translateY(20px);
    transition: transform .25s ease;
}

.modal-overlay.open .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--line);
}

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

.modal-close {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    min-height: auto;
    transition: background .15s, color .15s;
}

.modal-close:hover {
    background: var(--panel-soft);
    color: var(--text);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-body .form-grid {
    gap: 14px;
}

.modal-body label {
    margin-bottom: 2px;
}

.modal-body .actions {
    margin-top: 10px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

/* Add-button trigger for modals */
.add-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 9px 18px;
    border: 1px solid var(--primary);
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    font-size: 14px;
    transition: background .15s, box-shadow .15s;
}

.add-btn:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(20, 108, 95, .25);
}

.add-btn .plus {
    font-size: 18px;
    line-height: 1;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.section-header h2 {
    margin: 0;
    font-size: 18px;
}

.modal.wide {
    width: min(840px, 100%);
}

@media (max-width: 780px) {
    .modal-overlay {
        padding: 12px;
    }

    .modal {
        width: 100%;
        max-height: calc(100vh - 24px);
    }

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

/* ── Table Action Column Fix ── */
td.actions {
    display: table-cell !important;
    vertical-align: middle;
}

td.actions > * {
    display: inline-flex !important;
    vertical-align: middle;
}

td.actions > * + * {
    margin-left: 8px;
}

td.actions form {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

@media print {
    .sidebar,
    .topbar,
    .actions,
    .alert {
        display: none !important;
    }

    .main {
        margin: 0;
        padding: 0;
    }

    body {
        background: #fff;
        color: #000;
    }
}

/* ── Profile Dropdown ── */
.profile-dropdown {
    position: relative;
}

.profile-dropdown .user-pill {
    cursor: pointer;
    border: 1px solid var(--line);
    background: var(--panel-soft);
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    transition: background .15s, border-color .15s;
    min-height: auto;
}

.profile-dropdown .user-pill:hover {
    background: var(--panel);
    border-color: var(--primary);
}

.profile-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .15);
    z-index: 1100;
    padding: 6px 0;
    animation: profileMenuIn .15s ease;
}

@keyframes profileMenuIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.profile-menu.open {
    display: block;
}

.profile-menu a {
    display: block;
    padding: 10px 16px;
    font-size: 13px;
    color: var(--text);
    text-decoration: none;
    transition: background .12s;
}

.profile-menu a:hover {
    background: var(--panel-soft);
}

.profile-menu-divider {
    height: 1px;
    background: var(--line);
    margin: 4px 0;
}

/* ── Profile Page ── */
.profile-page {
    max-width: 680px;
    margin: 0 auto;
}

/* Profile Header Card */
.profile-header-card {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 24px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.profile-avatar {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.5px;
    box-shadow: 0 4px 14px rgba(20, 108, 95, .25);
}

.profile-header-info {
    flex: 1;
    min-width: 0;
}

.profile-name {
    margin: 0 0 2px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}

.profile-role {
    margin: 0 0 8px;
    font-size: 13px;
    color: var(--muted);
    font-weight: 500;
}

.profile-meta-badges {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.profile-meta-text {
    font-size: 12px;
    color: var(--muted);
}

/* Tabs */
.profile-tabs {
    display: flex;
    gap: 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}

.profile-tab {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 16px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    border-radius: 8px;
    transition: all .2s ease;
}

.profile-tab:hover {
    color: var(--text);
    background: var(--panel-soft);
}

.profile-tab.active {
    color: #fff;
    background: var(--primary);
    box-shadow: 0 2px 8px rgba(20, 108, 95, .2);
}

.profile-tab-icon {
    font-size: 15px;
    line-height: 1;
}

/* Profile Card */
.profile-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

.profile-card-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--line);
}

.profile-card-header h3 {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.profile-card-header p {
    margin: 0;
    font-size: 13px;
    color: var(--muted);
    line-height: 1.5;
}

.profile-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 24px;
}

.profile-form-stack {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 24px;
    max-width: 400px;
}

.profile-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.profile-field label {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    display: block;
}

.profile-field input {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    transition: border-color .2s, box-shadow .2s;
}

.profile-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(20, 108, 95, .1);
}

.profile-field input:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.profile-readonly {
    padding: 10px 12px;
    background: var(--panel-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14px;
    color: var(--muted);
    min-height: 40px;
    display: flex;
    align-items: center;
}

.profile-card-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--line);
    background: var(--panel-soft);
    display: flex;
    justify-content: flex-end;
}

.profile-card-footer button.primary {
    padding: 10px 24px;
    font-size: 14px;
    border-radius: 8px;
    font-weight: 700;
    transition: background .15s, box-shadow .15s;
}

.profile-card-footer button.primary:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(20, 108, 95, .25);
}

@media (max-width: 600px) {
    .profile-header-card {
        flex-direction: column;
        text-align: center;
    }

    .profile-meta-badges {
        justify-content: center;
    }

    .profile-form-grid {
        grid-template-columns: 1fr;
        padding: 16px;
    }

    .profile-form-stack {
        padding: 16px;
    }

    .profile-card-header {
        padding: 16px;
    }

    .profile-card-footer {
        padding: 12px 16px;
    }

    .profile-tab {
        padding: 10px 10px;
        font-size: 12px;
    }
}

/* ── Section Header Actions ── */
.section-header-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

