:root {
    /* Color Palette - Premium Blue/Indigo Theme */
    --primary-hue: 220;
    --primary: hsl(var(--primary-hue), 70%, 50%);
    --primary-dark: hsl(var(--primary-hue), 70%, 40%);
    --primary-light: hsl(var(--primary-hue), 70%, 95%);

    --secondary: hsl(260, 60%, 55%);
    --accent: hsl(330, 70%, 55%);

    /* Neutral Scales */
    --bg-body: hsl(220, 20%, 97%);
    --bg-card: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.8);

    --text-main: hsl(220, 30%, 20%);
    --text-muted: hsl(220, 20%, 50%);
    --text-light: hsl(220, 20%, 95%);

    --border-color: hsl(220, 20%, 90%);

    /* Row Striping Variables */
    --bg-row-even: var(--bg-body);
    --bg-row-hover: var(--primary-light);

    /* Semantic Colors */
    --success: hsl(150, 60%, 45%);
    --warning: hsl(35, 90%, 60%);
    --danger: hsl(0, 70%, 60%);

    /* Spacing & Layout */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
        0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 40px -10px rgba(0, 0, 0, 0.15);
    /* Soft, deep shadow */

    --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    --ease-out: cubic-bezier(0.25, 0.8, 0.25, 1);
}




#paymentModal .modal-content {
    width: 100%;
    height: 100%;
}

[data-theme="dark"] {
    --bg-body: hsl(220, 30%, 10%);
    --bg-card: hsl(220, 30%, 15%);
    --bg-glass: rgba(20, 25, 40, 0.8);

    --text-main: hsl(220, 20%, 95%);
    --text-muted: hsl(220, 20%, 65%);
    --text-light: hsl(220, 20%, 95%);

    --border-color: hsl(220, 30%, 25%);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 40px -10px rgba(0, 0, 0, 0.5);

    --primary-light: hsl(var(--primary-hue), 70%, 20%);

    /* Dark Mode Striping: Slightly lighter than card for visibility */
    --bg-row-even: rgba(255, 255, 255, 0.03);
    --bg-row-hover: rgba(255, 255, 255, 0.06);
}

/* Base Reset & Typography */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s, color 0.3s;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    line-height: 1.25;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.025em;
}

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

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

/* Utilities */
.container {
    width: 100%;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 20px;
    padding-right: 20px;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow 0.2s var(--ease-out);
}

/* Glassmorphism Effect */
.glass-panel {
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: var(--shadow-lg);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s var(--ease-out);
    gap: 8px;
    font-size: 0.95rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.35);
}

.btn-primary:active {
    transform: translateY(0);
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-main);
    font-size: 1rem;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-input:disabled {
    background: var(--bg-body);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.5s var(--ease-out) forwards;
}

/* Layout Grid */
.layout-wrapper {
    display: flex;
    min-height: 100vh;
    background: var(--bg-body);
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--bg-card);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 50;
    transition: transform 0.3s var(--ease-out);
}

.sidebar-header {
    height: 70px;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--primary);
    color: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.sidebar-nav {
    flex: 1;
    padding: 1.5rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    transition: all 0.2s;
}

.nav-item:hover,
.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-item.logout {
    color: var(--danger);
}

.nav-item.logout:hover {
    background: var(--danger);
    color: white;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: 260px;
    /* Width of sidebar */
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Topbar */
.topbar {
    height: 70px;
    background: var(--bg-glass);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar-title h2 {
    font-size: 1.25rem;
    margin: 0;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-name {
    font-weight: 500;
    font-size: 0.9rem;
}

.avatar {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
}

/* Page Body */
.page-body {
    padding: 1rem 2rem;
    flex: 1;
}

/* Stats Logic */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--bg-card);
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    transition: box-shadow 0.2s var(--ease-out), transform 0.2s var(--ease-out);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-content h3 {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stat-content .value {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.active {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
    }

    .main-content {
        margin-left: 0;
    }

    #mobile-menu-toggle {
        display: block !important;
    }
}

/* Data Tables */
.table-container {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    overflow: hidden;
    margin-top: 1rem;
}

.table-header {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
}

.table-title h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.table-actions {
    display: flex;
    gap: 10px;
}

.search-input {
    padding: 0.45rem 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    min-width: 220px;
    background: var(--bg-body);
    color: var(--text-main);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

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

th {
    background: var(--bg-body);
    padding: 0.6rem 1.25rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.7rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

td {
    padding: 0.7rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-main);
    vertical-align: middle;
    line-height: normal !important;
}

tbody tr:last-child td {
    border-bottom: none;
}

/* Striping & Hover */
tbody tr:nth-child(even) td {
    background: var(--bg-row-even);
}

tbody tr:hover td {
    background: var(--bg-row-hover);
    transition: background 0.2s;
}

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.badge-success {
    background: hsla(152, 62%, 42%, 0.12);
    color: var(--success);
}

.badge-warning {
    background: hsla(38, 92%, 55%, 0.12);
    color: var(--warning);
}

.badge-danger {
    background: hsla(0, 68%, 58%, 0.12);
    color: var(--danger);
}

.badge-neutral {
    background: var(--bg-body);
    color: var(--text-muted);
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.2s;
    padding: 20px;
}

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

.modal-content {
    background: var(--bg-card);
    width: 100%;
    max-width: 700px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    transform: translateY(10px);
    transition: transform 0.2s;
    border: 1px solid var(--border-color);
    max-height: 90vh;
}

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

.modal-header h3 {
    margin: 0;
}

.modal-body {
    padding: 1rem 1.5rem;
    overflow-y: auto;
    height: 65vh;
}

.modal-footer {
    padding: 1.5rem;
    background: var(--bg-body);
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.close-modal {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--text-muted);
}

/* Print Styles */
@media print {

    /* Hide non-printable elements */
    .sidebar,
    .topbar,
    .filter-bar,
    .btn,
    .expand-icon,
    #theme-toggle {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }

    .layout-wrapper {
        background: white !important;
    }

    .card,
    .table-container,
    .modal-content {
        box-shadow: none !important;
        border: none !important;
    }

    body {
        background: white !important;
        color: #1e293b !important;
        /* Dark slate for better readability than pure black */
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    table {
        width: 100% !important;
        border-collapse: collapse !important;
        font-size: 9pt;
        /* Slightly smaller for density */
    }

    th,
    td {
        border: 1px solid #e2e8f0 !important;
        padding: 6px 8px !important;
        color: #334155 !important;
    }

    th {
        background-color: #f1f5f9 !important;
        /* Light slate background */
        color: #0f172a !important;
        /* Darker text */
        font-weight: 700 !important;
        border-bottom: 2px solid #64748b !important;
    }

    a {
        text-decoration: none !important;
        color: #2563eb !important;
        /* Primary Blue */
    }

    /* Force Light Theme Striping */
    tbody tr:nth-child(even) td {
        background-color: #f8fafc !important;
        /* Forces Light Gray even if Dark Mode var is set */
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* METRICS PRINT STYLES */
    .metrics-container {
        display: block !important;
        width: 100% !important;
        break-inside: avoid;
        margin-bottom: 20px !important;
    }

    .metrics-container .date-filter-section,
    .trend-indicator {
        display: none !important;
    }

    .metrics-grid {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 12px !important;
    }

    .metric-card {
        border: 1px solid #e2e8f0 !important;
        background: #f8fafc !important;
        /* Very subtle background */
        padding: 10px !important;
        box-shadow: none !important;
        margin: 0 !important;
        border-radius: 6px !important;
        /* Keep the colored left border from default styles if possible, else force it */
        border-left: 4px solid #3b82f6 !important;
        /* Vivid Blue Brand Color */
    }

    .metric-title {
        color: #64748b !important;
        font-size: 8pt !important;
        font-weight: 600 !important;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .metric-value {
        color: #0f172a !important;
        font-size: 12pt !important;
        font-weight: 700 !important;
        margin-top: 4px;
    }

    .metric-subtext {
        font-size: 8pt !important;
        color: #94a3b8 !important;
    }

    /* Header Styling */
    .print-header {
        display: block !important;
        margin-bottom: 30px;
        border-bottom: 3px solid #3b82f6;
        /* Brand Line */
        padding-bottom: 15px;
    }

    .print-header h1 {
        color: #3b82f6 !important;
        /* Brand Blue */
    }

    /* Grand Total Row */
    .grand-total-row td {
        background-color: #eff6ff !important;
        /* Light Blue tint */
        border-top: 2px solid #3b82f6 !important;
        border-bottom: 2px solid #3b82f6 !important;
        color: #1e3a8a !important;
        /* Dark Blue Text */
        font-weight: 800 !important;
    }

    /* Badges */
    .badge {
        border: 1px solid #e2e8f0;
        padding: 2px 8px;
    }

    .badge-success {
        background-color: #dcfce7 !important;
        color: #166534 !important;
        border-color: #bbf7d0 !important;
    }

    .badge-warning {
        background-color: #fef3c7 !important;
        color: #92400e !important;
        border-color: #fde68a !important;
    }

    .badge-danger {
        background-color: #fee2e2 !important;
        color: #991b1b !important;
        border-color: #fecaca !important;
    }
}

/* Responsive Tenant Cards */
.mobile-tenant-cards {
    display: none;
    padding: 1rem;
    flex-direction: column;
    gap: 12px;
}

@media (max-width: 768px) {

    #tenantTable,
    .table-header .table-actions select {
        display: none !important;
    }

    .table-header {
        padding: 1rem;
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .search-input {
        min-width: unset;
        width: 100%;
    }

    .mobile-tenant-cards {
        display: flex;
    }
}

.tenant-mobile-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}

.tenant-mobile-card:active {
    transform: scale(0.98);
    background: var(--bg-row-hover);
}

.tenant-mobile-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.tenant-mobile-card .tenant-info {
    display: flex;
    align-items: center;
}

.tenant-mobile-card .tenant-name {
    font-weight: 600;
    color: var(--text-main);
    font-size: 1rem;
}

.tenant-mobile-card .landlord-name {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.tenant-mobile-card .card-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.tenant-mobile-card .detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tenant-mobile-card .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tenant-mobile-card .value {
    font-size: 0.9rem;
    font-weight: 500;
}

.tenant-mobile-card .value.balance {
    font-family: monospace;
    color: var(--primary);
    font-weight: 700;
    font-size: 1rem;
}