/* ============================================
   CSS CUSTOM PROPERTIES
   ============================================ */
:root {
    /* Colors */
    --color-primary: #1f5fa8;
    --color-primary-dark: #174e7d;
    --color-primary-light: #2d7bd4;
    --color-text: #22324a;
    --color-text-muted: #6c7a92;
    --color-bg: #f5f8ff;
    --color-white: #fff;
    --color-danger: #dc3545;
    --color-success: #2aa65f;
    --color-success-dark: #1f8a4d;
    --color-danger-btn: #e85d5d;
    --color-danger-btn-dark: #d94848;
    --color-border: #dce7f5;
    --color-border-light: #e7edf7;
    --color-header-bg-start: #0f4c81;
    --color-header-bg-end: #2c6db2;
    --color-nav-bg-start: #174e7d;
    --color-nav-bg-end: #1f5fa8;
    --color-table-header-start: #1f5fa8;
    --color-table-header-end: #2d7bd4;
    --color-row-hover: #f7fbff;
    --color-row-stripe: #f9fbff;
    --color-row-alt: #f0f4ff;
    --color-card-bg: #fff;
    --color-footer-bg: #333;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 18px;
    --radius-2xl: 24px;
    --radius-pill: 50px;
    --radius-btn: 8px;

    /* Shadows */
    --shadow-sm: 0 2px 6px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 20px rgba(17, 54, 100, 0.06);
    --shadow-lg: 0 10px 26px rgba(17, 54, 100, 0.08);
    --shadow-xl: 0 12px 35px rgba(19, 76, 140, 0.12);
    --shadow-btn: 0 6px 14px rgba(31, 95, 168, 0.2);
    --shadow-dropdown: 0 10px 24px rgba(17, 54, 100, 0.12);

    /* Transitions */
    --transition-fast: 0.2s ease;
}

/* ============================================
   BASE STYLES
   ============================================ */
body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    color: var(--color-text);
    background: linear-gradient(135deg, #f5f8ff 0%, #eef4ff 45%, #fdf7ff 100%);
    text-align: right;
    min-height: 100vh;
}

.app-body {
    padding: 1rem 1rem 2.5rem;
}

.site-shell {
    max-width: 1500px;
    margin: 0 auto;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(19, 76, 140, 0.12);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

a {
    color: var(--color-primary);
    transition: color var(--transition-fast), transform var(--transition-fast);
}

a:hover {
    color: var(--color-primary-dark);
}

.container {
    max-width: 1400px;
}

.content-wrapper {
    padding: 0.5rem 0 4rem;
}

/* ============================================
   COLOR UTILITIES
   ============================================ */
.row-positive {
    background-color: #c1dafb;
}

.row-negative {
    background-color: #f4f8ff;
}

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

td.negativetd {
    color: var(--color-danger) !important;
}

.balance-cell {
    color: var(--color-danger);
    font-weight: bold;
}

/* ============================================
   TABLE STYLES
   NOTE: .table-boardered is a misspelling of .table-bordered
   that is still referenced in some templates — kept intentionally
   as an alias below. Don't remove without updating those templates.
   ============================================ */
.table-custom tbody tr:nth-child(4n+1),
.table-custom tbody tr:nth-child(4n+2) {
    background-color: var(--color-row-alt);
    color: var(--color-text);
}

.table,
.table-bordered,
.table-boardered {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    direction: rtl;
    overflow: hidden;
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.table th,
.table td,
.table-bordered th,
.table-bordered td,
.table-boardered th,
.table-boardered td {
    padding: 0.85rem 0.9rem;
    border-bottom: 1px solid var(--color-border-light);
    border-left: 0;
    border-right: 0;
    text-align: right;
    vertical-align: middle;
}

.table thead th,
.table-bordered thead th,
.table-boardered thead th {
    background: linear-gradient(90deg, var(--color-table-header-start) 0%, var(--color-table-header-end) 100%);
    color: var(--color-white);
    font-weight: 600;
    border-bottom: none;
}

.table tbody tr:hover,
.table-bordered tbody tr:hover,
.table-boardered tbody tr:hover {
    background-color: var(--color-row-hover);
}

.table-striped > tbody > tr:nth-of-type(odd) > td,
.table-striped > tbody > tr:nth-of-type(odd) > th {
    background-color: var(--color-row-stripe);
}

.table-bordered tr.record-row,
.table-boardered tr.record-row,
.table tr.record-row {
    border-bottom: 3px solid #4c7bb7;
}

.table-bordered tr.record-row td,
.table-boardered tr.record-row td,
.table tr.record-row td {
    border-bottom: 3px solid #4c7bb7;
}

.table-bordered tr.mobile-row,
.table-boardered tr.mobile-row,
.table tr.mobile-row {
    border-bottom: 1px solid var(--color-border-light);
}

.table-bordered tr.mobile-row td,
.table-boardered tr.mobile-row td,
.table tr.mobile-row td {
    border-bottom: 1px solid var(--color-border-light);
}

.myTables {
    margin: 0 auto 1.5rem;
    padding: 1.25rem;
    max-width: 650px;
    border: 1px solid var(--color-border);
    background: linear-gradient(135deg, #f7fbff 0%, #f1f6ff 100%);
    font-size: medium;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
}

.cost-table-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.table-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.table-toolbar .btn {
    margin: 0;
}

.table-toolbar.after-table {
    margin-top: 0.75rem;
    margin-bottom: 0;
}

.cost-table-search {
    width: 100%;
    flex-wrap: wrap;
}

.table-toolbar label {
    flex: 0 0 auto;
    font-weight: 600;
}

.table-toolbar input {
    flex: 1 1 180px;
    min-width: 0;
    margin: 0;
}

.tabulator {
    width: 100%;
    direction: rtl;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-white);
    color: var(--color-text);
    font-family: inherit;
    font-size: inherit;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.tabulator .tabulator-header {
    color: var(--color-white);
    background: #4a90c2;
    border-bottom: 0;
}

.tabulator .tabulator-header .tabulator-col {
    color: var(--color-white);
    background: transparent;
    border-left: 1px solid rgba(255, 255, 255, 0.15);
    text-align: right;
}

.tabulator .tabulator-tableholder {
    overflow-x: auto;
}

.tabulator-row {
    min-height: 48px;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border-light);
}

.tabulator-row:nth-child(even) {
    background: var(--color-row-stripe);
}

.tabulator-row:hover {
    background: var(--color-row-hover) !important;
}

.tabulator-row .tabulator-cell {
    display: flex;
    align-items: center;
    border-left: 0;
    border-right: 0;
    text-align: right;
    white-space: normal;
    overflow-wrap: anywhere;
}

.tabulator-row.row-positive {
    background-color: #c1dafb;
}

.tabulator-row.row-negative {
    background-color: #f4f8ff;
}

.tabulator .tabulator-footer {
    padding: 0.65rem;
    direction: rtl;
    background: var(--color-white);
    border-top: 1px solid var(--color-border-light);
}

.tabulator .tabulator-page {
    min-width: 2rem;
    padding: 0.35rem 0.55rem;
    margin: 0 0.15rem;
    color: var(--color-primary-dark);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-white);
}

.tabulator .tabulator-page.active,
.tabulator .tabulator-page:hover {
    color: var(--color-white);
    border-color: var(--color-primary);
    background: var(--color-primary);
}

/* The costs table becomes a two-line card per record on phones. */
@media (max-width: 576px) {
    .myTables {
        padding: 0.75rem;
    }

    #costTable,
    #costTable tbody {
        display: block;
        width: 100% !important;
    }

    #costTable thead {
        display: none;
    }

    #costTable tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas:
            "date amount"
            "title category";
        width: 100%;
        box-sizing: border-box;
        margin-bottom: 0.75rem;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        overflow: hidden;
        background: var(--color-white);
    }

    #costTable tbody td {
        display: flex;
        align-items: center;
        gap: 0.4rem;
        min-width: 0;
        width: auto !important;
        box-sizing: border-box;
        padding: 0.6rem 0.45rem;
        border-bottom: 1px solid var(--color-border-light);
        overflow-wrap: anywhere;
    }

    #costTable tbody td:nth-child(1) { grid-area: date; }
    #costTable tbody td:nth-child(2) { grid-area: title; border-bottom: 0; }
    #costTable tbody td:nth-child(3) { grid-area: amount; }
    #costTable tbody td:nth-child(4) { grid-area: category; border-bottom: 0; }

    #costTable tbody td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        color: var(--color-text-muted);
        font-size: 0.8rem;
        font-weight: 600;
    }

    #costTable tbody td > * {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    #costTable tbody td[colspan] {
        display: block;
        grid-column: 1 / -1;
        text-align: center;
    }

    #costTable tbody td[colspan]::before {
        content: none;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.text-center {
    text-align: center;
}

.form-group-narrow {
    max-width: 250px;
    margin: auto;
}

.form-group-narrow .form-label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
    color: var(--color-text);
}

.form-group-narrow .form-control {
    width: 100%;
    margin-bottom: 1rem;
}

.form-group-narrow .form-control:last-of-type {
    margin-bottom: 0;
}

/* ============================================
   FORM STYLES
   ============================================ */
.formContainer {
    display: flex;
    justify-content: center;
    align-items: center;
    background: #9bc1f2;
    max-width: 480px;
    padding: 1.25rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid #e2ebf8;
    margin: 1.25rem auto;
}

/* Keep the dashboard payment/selection panel close to the navigation header. */
.dashboard-payment-form {
    margin-top: -0.75rem;
}

.dashboard-payment-action {
    display: flex;
    justify-content: center;
    margin-top: 0.75rem;
}

/* ============================================
   DASHBOARD REPORT TABS
   ============================================ */
.dashboard-reports {
    margin-top: 40px;
}

.dashboard-tab-navigation {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--color-border);
}

.dashboard-tab-navigation .tab-button {
    flex: 0 1 auto;
    padding: 0.65rem 1.1rem;
    color: var(--color-primary-dark) !important;
    background: #e7f0fb !important;
    border: 1px solid #b9d0ea !important;
    border-radius: var(--radius-sm);
    font-weight: 600;
    transition: background-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}

.dashboard-tab-navigation .tab-button.sharp-bottom {
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.dashboard-tab-navigation .tab-button:hover,
.dashboard-tab-navigation .tab-button.active {
    color: var(--color-white) !important;
    background: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
}

.dashboard-tab-navigation .tab-button:focus-visible {
    outline: 3px solid rgba(45, 123, 212, 0.35);
    outline-offset: 2px;
}

.dashboard-tab-content {
    display: none;
    padding: 20px 0;
}

.dashboard-tab-content.is-active {
    display: block;
}

@media (max-width: 576px) {
    .dashboard-tab-navigation {
        flex-wrap: nowrap;
        gap: 6px;
    }

    .dashboard-tab-navigation .tab-button {
        flex: 1 1 0;
        min-width: 0;
        padding: 0.6rem 0.3rem;
        font-size: 0.7rem;
        white-space: nowrap;
    }
}

.readonly-field {
    background-color: #f5f8ff;
    color: var(--color-text-muted);
    border-color: #dbe4f0;
    cursor: not-allowed;
}

.form-control,
.form-select,
input,
select,
textarea {
    border: 1px solid #d8e4f4;
    border-radius: var(--radius-md);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.02);
}

[dir="rtl"] .form-select {
    background-position: left 0.75rem center;
    padding-right: 0.75rem;
    padding-left: 2.25rem;
}

/* ============================================
   BUTTON STYLES
   ============================================ */
button:not(.navbar-toggler):not(.btn-close) {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    color: white;
    border: none;
    padding: 0.45rem 1rem;
    cursor: pointer;
    border-radius: var(--radius-btn);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

button:not(.navbar-toggler):not(.btn-close):hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-btn);
}

.btn.small-action-btn {
    padding: 2px 8px;
    font-size: 12px;
    line-height: 1.2;
    margin-top: 0;
    margin-bottom: 0;
    vertical-align: middle;
}

.btn {
    display: inline-block;
    padding: 0.6rem 1rem;
    text-decoration: none;
    border-radius: var(--radius-btn);
    font-size: 0.95rem;
    margin-top: 0.75rem;
    border: 1px solid transparent;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-success {
    background: linear-gradient(135deg, var(--color-success) 0%, var(--color-success-dark) 100%);
    color: white;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    color: white;
}

.btn-outline-primary,
.btn-outline-secondary,
.btn-outline-danger {
    background: var(--color-white);
}

.btn-fail {
    background: linear-gradient(135deg, var(--color-danger-btn) 0%, var(--color-danger-btn-dark) 100%);
    color: white;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Center callback page buttons */
.callback-page .callback-buttons {
    text-align: center;
    margin-top: 0.5rem;
}

.callback-page .callback-buttons .btn {
    display: inline-block;
    margin: 0.35rem 0.5rem;
}

/* ============================================
   MESSAGE STYLES
   ============================================ */
.message {
    padding: 15px;
    font-size: 18px;
    border-radius: var(--radius-sm);
    display: inline-block;
    margin-bottom: 20px;
    background-color: #28a745;
}

.message.success {
    background-color: #d4edda;
    color: #155724;
}

.message.error {
    background-color: #f8d7da;
    color: #721c24;
}

/* ============================================
   POPUP STYLES
   ============================================ */
.popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 15px;
    overflow-y: auto;
}

.popup-content {
    background: white;
    padding: 25px;
    border-radius: var(--radius-sm);
    width: 100%;
    max-width: 500px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    direction: rtl;
    text-align: right;
    margin: auto;
}

.popup-content h5 {
    margin-bottom: 20px;
    color: #333;
    font-size: 1.1rem;
}

.popup-content input {
    width: 100%;
    margin-bottom: 10px;
    padding: 10px;
    direction: ltr;
    text-align: left;
    font-size: 16px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.popup-content input:invalid {
    border-color: var(--color-danger);
}

.error-message {
    color: var(--color-danger);
    font-size: 13px;
    display: block;
    margin-bottom: 10px;
    min-height: 18px;
}

/* ============================================
   HEADER SECTION
   ============================================ */
.header-section {
    text-align: center;
    background: linear-gradient(90deg, var(--color-header-bg-start) 0%, var(--color-header-bg-end) 100%);
    color: var(--color-white);
    padding: 1rem 0;
    z-index: 1030;
    position: relative;
}

.header-section .title {
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: 0.01em;
}

.header-section .user-info {
    font-size: 0.95rem;
    color: #eff6ff;
    display: inline-block;
    padding-left: 4px;
    white-space: nowrap;
}

.header-section .form-select {
    min-width: 220px;
    background-position: left 0.75rem center;
    border-radius: var(--radius-pill);
}

/* ============================================
   NAVBAR STYLES
   ============================================ */
.navbar {
    padding: 0.35rem 0;
    min-height: auto;
    text-align: right;
    background: linear-gradient(90deg, var(--color-nav-bg-start) 0%, var(--color-nav-bg-end) 100%);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    direction: rtl;
}

.navbar .container-fluid {
    justify-content: flex-end;
}

.navbar .navbar-collapse {
    justify-content: flex-end;
}

.navbar-toggler {
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
    border-color: rgba(255, 255, 255, 0.55);
    border-radius: var(--radius-md);
    background-color: rgba(255, 255, 255, 0.12);
    margin-left: auto;
    margin-right: 0;
}

.navbar-toggler:hover {
    background-color: rgba(255, 255, 255, 0.22);
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.3);
}

.navbar-toggler-icon {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255%2C255%2C255%2C0.95%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e");
}

.navbar-nav {
    align-items: center;
    margin-left: auto;
    margin-right: 0;
    direction: rtl;
}

.navbar-nav .nav-item {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.navbar-nav .nav-link {
    padding: 0.5rem 0.8rem;
    font-size: 0.95rem;
    line-height: 1.2;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    text-align: right;
    color: #f7fbff;
    border-radius: var(--radius-pill);
}

.navbar-nav .nav-link:hover,
.navbar-nav .nav-link:focus,
.navbar-nav .nav-item.active > .nav-link {
    background: rgba(255, 255, 255, 0.14);
    color: var(--color-white);
}

.navbar-nav .dropdown {
    display: flex;
    align-items: center;
}

.navbar-nav .dropdown-toggle {
    display: inline-flex;
    align-items: center;
    text-align: right;
    padding-right: 0.8rem;
    padding-left: 0.8rem;
    color: #f7fbff;
}

/* ============================================
   DROPDOWN MENU STYLES
   ============================================ */
.dropdown-menu {
    direction: rtl;
    text-align: right;
    min-width: 180px;
    width: auto;
    font-size: 0.95rem;
    margin-top: 0.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-dropdown);
}

.navbar-nav .dropdown-menu {
    min-width: 190px;
}

.dropdown-item {
    text-align: right;
    padding: 0.55rem 0.9rem;
    font-size: 0.95rem;
}

.dropdown-item:hover {
    background: #f2f7ff;
}

.navbar-nav .dropdown-menu .dropdown-menu {
    right: 100%;
    left: auto;
    margin-right: 0.125rem;
}

/* RTL Dropdown Fixes */
[dir="rtl"] .dropdown-menu {
    right: 0;
    left: auto;
    text-align: right;
}

[dir="rtl"] .dropdown-item {
    text-align: right;
    padding-right: 1rem;
    padding-left: 1rem;
}

[dir="rtl"] .dropdown-toggle::after {
    margin-right: 0;
    margin-left: 0.3rem;
    float: left;
}

/* ============================================
   FOOTER
   ============================================ */
footer {
    background-color: var(--color-footer-bg);
    color: white;
    text-align: center;
    padding: 0.75rem 0;
    position: fixed;
    bottom: 0;
    width: 100%;
    z-index: 900;
}

/* ============================================
   BUILDING CHARGE AMOUNTS PAGE
   ============================================ */
.charge-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 0 40px;
    direction: rtl;
    text-align: right;
}

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

.charge-title {
    margin: 0;
    color: #1f2d3d;
    font-weight: 700;
}

.charge-badge {
    background: linear-gradient(90deg, #eef5ff, #f7f3ff);
    color: #3556a8;
    border: 1px solid #d8e3ff;
    border-radius: var(--radius-pill);
    padding: 0.55rem 0.9rem;
    font-size: 0.9rem;
    white-space: nowrap;
}

.charge-card {
    background: var(--color-white);
    border-radius: var(--radius-xl);
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    border: 1px solid #eef2ff;
    overflow: hidden;
}

.charge-card__body {
    padding: 18px;
}

.edit-row-card {
    background: var(--color-white);
    border: 1px solid #e9eefc;
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 14px;
}

.edit-row-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.edit-row-fields {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

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

.field-group label {
    font-size: 0.9rem;
    color: #34495e;
    font-weight: 600;
}

.field-group input {
    text-align: left;
    direction: ltr;
}

.edit-row-description {
    margin-top: 10px;
    background: #f8f9fb;
    color: #5f6b7a;
    border-radius: var(--radius-md);
    padding: 0.65rem 0.8rem;
    font-size: 0.9rem;
}

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: #6c757d;
}

.empty-state__icon {
    font-size: 2rem;
    margin-bottom: 10px;
}

/* ============================================
   MOBILE STYLES
   ============================================ */
.mobile-row {
    display: none;
}

.mobile-title-cell {
    display: none;
}

@media (max-width: 768px) {
    .charge-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .charge-card__body {
        padding: 12px;
    }

    .mobile-row {
        display: table-row;
        font-size: medium;
    }

    .mobile-title-cell {
        display: table-cell;
        padding-left: 16px;
        border-top: none;
    }

    .mobile-hide {
        display: none;
    }

    /* Remove bold border from record-row in mobile (it's not the last row of the record) */
    .table-bordered tr.record-row,
    .table-boardered tr.record-row,
    .table tr.record-row {
        border-bottom: 1px solid #ddd;
    }

    .table-bordered tr.record-row td,
    .table-boardered tr.record-row td,
    .table tr.record-row td {
        border-bottom: 1px solid #ddd;
    }

    /* Add bold border to mobile-row (it's the last row of each record) */
    .table-bordered tr.mobile-row,
    .table-boardered tr.mobile-row,
    .table tr.mobile-row {
        border-bottom: 3px solid #666;
    }

    .table-bordered tr.mobile-row td,
    .table-boardered tr.mobile-row td,
    .table tr.mobile-row td {
        border-bottom: 3px solid #666;
    }
}

@media (max-width: 480px) {
    .popup-overlay {
        padding: 10px;
    }

    .popup-content {
        padding: 15px;
    }

    .popup-content input {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Costs are displayed as compact cards on phones:
   date / amount / category, then the title across the full row. */
@media (max-width: 576px) {
    #costTable,
    #costTable .tabulator,
    #costTable .tabulator-table,
    #costTable .tabulator-tableholder {
        width: 100%;
        background: var(--color-white);
    }

    #costTable .tabulator-table {
        display: block;
        min-width: 100%;
    }

    #costTable .tabulator-header {
        display: none;
    }

    #costTable .tabulator-tableholder {
        overflow: visible;
    }

    #costTable .tabulator-row {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        grid-template-rows: 42px 42px;
        grid-template-areas:
            "date amount category"
            "title title title";
        align-content: start;
        width: 100%;
        min-height: 0;
        height: 84px !important;
        margin-bottom: 0.75rem;
        overflow: hidden;
        border: 1px solid var(--color-border);
        border-radius: var(--radius-md);
        background: var(--color-white);
        box-shadow: var(--shadow-sm);
    }

    #costTable .tabulator-row .tabulator-cell {
        min-width: 0;
        width: auto !important;
        height: 42px !important;
        min-height: 42px;
        box-sizing: border-box;
        padding: 0.55rem 0.45rem;
        align-self: start;
        line-height: 1.35;
        border-left: 1px solid var(--color-border-light);
        border-bottom: 1px solid var(--color-border-light);
        overflow-wrap: anywhere;
    }

    #costTable .tabulator-row .cost-date {
        grid-area: date;
    }

    #costTable .tabulator-row .cost-amount {
        grid-area: amount;
    }

    #costTable .tabulator-row .cost-category {
        grid-area: category;
    }

    #costTable .tabulator-row .cost-title {
        grid-area: title;
        height: 42px !important;
        border-bottom: 0;
        border-left: 0;
    }

    #costTable .tabulator-row .cost-title a {
        min-width: 0;
        overflow-wrap: anywhere;
    }
}

/* ============================================
   TABLET AND MOBILE NAVIGATION
   ============================================ */
@media (max-width: 991px) {
    .header-section .title {
        font-size: 20px;
        margin-bottom: 8px;
    }

    .header-section .user-info {
        display: block;
        margin: 5px 0;
    }

    .header-section form {
        display: block;
        margin-top: 5px;
    }

    .header-section .form-select {
        width: 100%;
        max-width: 300px;
        margin: 0 auto;
    }

    .navbar {
        padding: 0.3rem 1rem;
    }

    .navbar-collapse {
        margin-top: 0.5rem;
    }

    .navbar-nav {
        width: 100%;
        align-items: stretch;
    }

    .navbar-nav .nav-item {
        display: block;
    }

    .navbar-nav .nav-link {
        padding: 0.5rem 1rem;
        font-size: 15px;
        border-bottom: 1px solid #e0e0e0;
        display: block;
        text-align: right;
    }

    .navbar-nav .nav-item:last-child .nav-link {
        border-bottom: none;
    }

    .navbar-nav .dropdown {
        display: block;
        position: relative;
    }

    .navbar-nav .dropdown-toggle {
        text-align: right;
        width: 100%;
        display: block;
    }

    .navbar-nav .dropdown-toggle::after {
        float: left;
        margin-top: 0.4rem;
        margin-right: 0 !important;
    }

    .navbar-nav .dropdown-menu {
        position: static !important;
        transform: none !important;
        float: none !important;
        left: auto !important;
        right: auto !important;
        top: auto !important;
        border: none;
        padding: 0;
        margin: 0;
        background-color: #f8f9fa;
        width: 100%;
        text-align: right;
    }

    .navbar-nav .dropdown-menu.show {
        display: block;
    }

    .navbar-nav .dropdown-item {
        padding: 0.5rem 2rem 0.5rem 1rem;
        font-size: 14px;
        border-bottom: 1px solid #e0e0e0;
        text-align: right;
    }

    .navbar-nav .dropdown-item:last-child {
        border-bottom: none;
    }
}

/* ============================================
   MODERN SITE-WIDE UI POLISH
   Shared by every page extending base.html.
   ============================================ */
:root {
    --color-surface-muted: #f7faff;
    --color-focus: rgba(45, 123, 212, 0.28);
    --shadow-card: 0 14px 34px rgba(25, 65, 115, 0.09);
}

body {
    font-size: 0.95rem;
    line-height: 1.7;
    -webkit-font-smoothing: antialiased;
}

.site-shell {
    backdrop-filter: blur(8px);
}

.header-section {
    padding: 1.35rem 0;
    background: linear-gradient(115deg, #103f70 0%, #1f5fa8 56%, #3688d6 100%);
}

.header-section .title {
    font-size: clamp(1.05rem, 2vw, 1.35rem);
}

.header-section .user-info {
    font-weight: 600;
}

.modern-navbar {
    box-shadow: 0 5px 16px rgba(10, 54, 102, 0.16);
}

.navbar-nav .nav-link {
    transition: background-color var(--transition-fast), color var(--transition-fast), transform var(--transition-fast);
}

.navbar-nav .nav-link:hover,
.navbar-nav .nav-link:focus-visible {
    transform: translateY(-1px);
}

.content-wrapper {
    min-height: 60vh;
}

.content-wrapper > .container {
    padding-top: clamp(1rem, 3vw, 2rem) !important;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--color-primary-dark);
    font-weight: 700;
    letter-spacing: -0.01em;
}

h4.text-center,
.myTables > h4.text-center,
.myTables > h5 {
    margin: 0 0 1.25rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--color-border);
}

.myTables {
    max-width: 1100px;
    padding: clamp(1rem, 2.5vw, 1.75rem);
    background: rgba(255, 255, 255, 0.88);
    box-shadow: var(--shadow-card);
}

.formContainer,
.formAc {
    width: min(100%, 520px);
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.94);
    padding: clamp(1.25rem, 4vw, 2rem);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-card);
}

.formContainer form,
.formAc {
    width: 100%;
}

.form-group-narrow {
    width: min(100%, 360px);
    max-width: none;
}

.form-group-narrow > label,
.form-group-narrow .form-label,
.field-group label {
    margin-top: 0.55rem;
    color: var(--color-primary-dark);
}

.form-control,
.form-select,
input,
select,
textarea {
    min-height: 42px;
    padding: 0.6rem 0.8rem;
    color: var(--color-text);
    background-color: var(--color-white);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast);
}

textarea.form-control,
textarea {
    min-height: 96px;
    resize: vertical;
}

.form-control:focus,
.form-select:focus,
input:focus,
select:focus,
textarea:focus {
    border-color: var(--color-primary-light);
    box-shadow: 0 0 0 0.22rem var(--color-focus);
    outline: none;
}

.btn {
    min-height: 42px;
    font-weight: 600;
    box-shadow: 0 4px 10px rgba(31, 95, 168, 0.12);
}

.btn:hover,
.btn:focus-visible {
    box-shadow: var(--shadow-btn);
}

.table,
.table-bordered,
.table-boardered {
    box-shadow: none;
    border: 1px solid var(--color-border);
}

.table thead th,
.table-bordered thead th,
.table-boardered thead th {
    padding-top: 0.95rem;
    padding-bottom: 0.95rem;
}

.table tbody tr,
.tabulator-row {
    transition: background-color var(--transition-fast), transform var(--transition-fast);
}

.table tbody tr:hover {
    transform: translateX(-2px);
}

.card {
    border: 1px solid var(--color-border) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-sm);
    background: var(--color-white);
}

.alert {
    border: 0;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.error-message {
    margin-top: 0.5rem;
    padding: 0.55rem 0.75rem;
    border-radius: var(--radius-sm);
    background: #fff1f2;
    color: #b42318;
}

.captcha-container {
    margin: 1rem 0;
    padding: 0.75rem;
    border: 1px dashed var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-surface-muted);
}

.captcha-container img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
}

.dashboard-payment-form {
    max-width: 380px;
    margin-right: auto;
    margin-left: auto;
}

.dashboard-payment-form form > div:first-child {
    width: min(100%, 360px);
    margin: 0 auto;
}

.dashboard-payment-form label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
    color: var(--color-primary-dark);
}

.dashboard-reports {
    max-width: 1100px;
    margin-right: auto;
    margin-left: auto;
    padding: clamp(1rem, 2.5vw, 1.75rem);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, 0.7);
    box-shadow: var(--shadow-card);
}

.dashboard-tab-content {
    padding: 1.25rem 0 0;
}

.dashboard-tab-content > div {
    min-height: 80px;
}

.charge-card,
.edit-row-card {
    box-shadow: var(--shadow-sm);
}

.charge-card__body {
    background: rgba(255, 255, 255, 0.65);
}

.account-list {
    display: grid;
    gap: 0.75rem;
    max-width: 850px;
    margin: 0 auto 1.5rem;
}

.account-card {
    overflow: hidden;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-white);
    box-shadow: var(--shadow-sm);
}

.account-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.9rem 1rem;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.account-card__header:hover {
    background: var(--color-surface-muted);
}

.account-card__details {
    display: none;
    padding: 1rem;
    border-top: 1px solid var(--color-border-light);
    background: var(--color-surface-muted);
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.6rem;
}

.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.9rem;
}

.message {
    max-width: 680px;
    margin: 2rem auto 1rem;
    box-shadow: var(--shadow-card);
}

.callback-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 1.25rem;
    background: linear-gradient(135deg, #edf5ff, #f8fbff 50%, #f5f0ff);
}

.callback-page > * {
    width: min(100%, 680px);
    text-align: center;
}

.callback-page h1,
.callback-page h2 {
    margin-bottom: 1rem;
}

.callback-buttons {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 0.6rem;
}

@media (max-width: 768px) {
    .app-body {
        padding: 0.5rem 0.5rem 2rem;
    }

    .site-shell {
        border-radius: var(--radius-xl);
    }

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

    .table-responsive,
    .myTables {
        overflow-x: auto;
    }

    .table {
        min-width: 560px;
    }

    .myTables .table {
        min-width: 0;
    }

    .dashboard-reports {
        padding: 0.85rem;
    }
}

@media (max-width: 480px) {
    .header-section {
        padding: 1rem 0;
    }

    .myTables {
        border-radius: var(--radius-md);
    }

    .table-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .table-toolbar .btn {
        width: 100%;
    }

    /* Keep the costs search control compact on narrow screens. */
    .cost-table-search {
        gap: 0.3rem;
    }

    .cost-table-search #costSearch,
    .turnover-table-search #turnoverSearch {
        flex: 0 0 36px;
        width: 100%;
        min-height: 36px;
        height: 36px;
        padding: 0.35rem 0.65rem;
        line-height: 1.25;
    }

    .dashboard-tab-navigation .tab-button {
        font-size: 0.78rem;
    }
}

/* Professional Tabulator appearance.
   The library stylesheet is loaded after this file on table pages, so these
   scoped selectors intentionally have higher specificity than its defaults. */
.myTables .tabulator .tabulator-header {
    overflow: hidden;
    border-bottom: 0;
    background: #4a90c2;
    color: var(--color-white);
}

.myTables .tabulator .tabulator-header .tabulator-col {
    min-height: 46px;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    background: transparent;
    color: var(--color-white);
}

.myTables .tabulator .tabulator-header .tabulator-col-content {
    padding: 0.7rem 0.8rem;
}

.myTables .tabulator .tabulator-footer {
    border-top: 1px solid var(--color-border);
    background: #f7faff;
    color: var(--color-text-muted);
}

.myTables .tabulator .tabulator-page {
    min-width: 2rem;
    padding: 0.35rem 0.55rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    color: var(--color-primary-dark);
}

.myTables .tabulator .tabulator-page.active,
.myTables .tabulator .tabulator-page:hover {
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: var(--color-white);
}

/* Match every regular HTML table heading, including pages that use a
   heading cell directly in a row instead of a <thead>. */
.table th,
.table-bordered th,
.table-boardered th,
.table thead th,
.table-bordered thead th,
.table-boardered thead th {
    padding: 0.7rem 0.8rem;
    border-bottom: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.2);
    background: #4a90c2;
    color: var(--color-white);
    font-weight: 600;
}
