:root {
    /* Light theme colors */
    --bg-primary: #f8f8f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f5f5f5;
    --text-primary: #333333;
    --text-secondary: #666666;
    --text-inverse: #ffffff;
    --border-color: rgba(0, 0, 0, 0.06);
    --border-color-strong: rgba(0, 0, 0, 0.1);
    --shadow: rgba(0, 0, 0, 0.08);
    --shadow-strong: rgba(0, 0, 0, 0.15);
    --header-bg: #1a1a1a;
    --stat-card-bg: #1a1a1a;
    --input-bg: #ffffff;
    --input-border: #ddd;
    --modal-overlay: rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] {
    /* Dark theme colors */
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #2a2a2a;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-inverse: #1a1a1a;
    --border-color: rgba(255, 255, 255, 0.1);
    --border-color-strong: rgba(255, 255, 255, 0.2);
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-strong: rgba(0, 0, 0, 0.5);
    --header-bg: #0d0d0d;
    --stat-card-bg: #252525;
    --input-bg: #2a2a2a;
    --input-border: #404040;
    --modal-overlay: rgba(0, 0, 0, 0.8);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Comfortaa', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border-radius: 16px;
    box-shadow: 0 4px 20px var(--shadow);
    overflow-x: hidden;
    border: 1px solid var(--border-color);
    transition: background-color 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    width: 100%;
}

header {
    background: var(--header-bg);
    color: var(--text-inverse);
    padding: 35px 30px;
    border-bottom: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
    position: relative; /* Cần để menu dropdown hoạt động đúng */
}

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

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
}

.header-right {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.header-buttons-desktop {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.current-user {
    color: white;
    font-weight: 500;
}

header h1 {
    font-size: 2.5em;
    margin: 0;
    color: white;
    font-weight: 300;
    letter-spacing: -0.5px;
}

/* Mobile Menu Toggle (Hamburger) */
.mobile-menu-toggle {
    display: none;
    flex-direction: column;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    gap: 4px;
    width: 32px;
    height: 32px;
    justify-content: center;
    align-items: center;
}

.mobile-menu-toggle span {
    width: 24px;
    height: 3px;
    background: white;
    border-radius: 2px;
    transition: all 0.3s ease;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(7px, 7px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

.mobile-user-menu-toggle {
    display: none;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
}

.mobile-user-menu {
    display: none;
    flex-direction: column;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 10px;
    margin-top: 10px;
    gap: 5px;
    border: 1px solid var(--border-color);
}

.mobile-menu-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 10px 15px;
    border-radius: 6px;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.mobile-menu-item:hover {
    background: var(--bg-primary);
    transform: translateX(2px);
}

.tabs {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    transition: all 0.3s ease;
}

.tab-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.9);
    padding: 14px 28px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.25s ease;
    font-weight: 400;
    white-space: nowrap;
}

.tab-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-1px);
}

.tab-btn.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-weight: 500;
    border-color: var(--bg-secondary);
    box-shadow: 0 2px 8px var(--shadow);
}

[data-theme="dark"] .tab-btn.active {
    background: var(--bg-tertiary);
    color: var(--text-inverse);
}

.tab-content {
    display: none;
    padding: 35px;
    background: var(--bg-secondary);
    transition: background-color 0.3s ease;
}

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

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
    margin-bottom: 45px;
}

.stat-card {
    background: var(--stat-card-bg);
    color: var(--text-inverse);
    padding: 28px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 3px 12px var(--shadow);
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
}

.stat-card h3 {
    font-size: 13px;
    opacity: 0.75;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    font-weight: 400;
}

.stat-number {
    font-size: 2.5em;
    font-weight: 300;
    color: white;
    letter-spacing: -1px;
}

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

.section-header h2 {
    color: #000;
    font-size: 1.8em;
    font-weight: 400;
    letter-spacing: -0.5px;
}

.info-text {
    color: #666;
    font-size: 14px;
    margin-top: 10px;
    line-height: 1.6;
}

.btn {
    padding: 12px 26px;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 400;
    transition: all 0.25s ease;
    letter-spacing: 0.3px;
}

.btn-primary {
    background: #000;
    color: white;
    border-color: #000;
}

.btn-primary:hover {
    background: #333;
    border-color: #333;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-color: var(--input-border);
    transition: all 0.25s ease;
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    opacity: 0.8;
    border-color: var(--border-color-strong);
    transform: translateY(-1px);
}

[data-theme="dark"] .btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-inverse);
}

.btn-danger {
    background: #dc3545;
    color: white;
    border-color: #dc3545;
}

.btn-danger:hover {
    background: #c82333;
    border-color: #bd2130;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.25);
}

.btn-success {
    background: #1a1a1a;
    color: white;
    border-color: #1a1a1a;
}

.btn-success:hover {
    background: #333;
    border-color: #333;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn-info {
    background: #17a2b8;
    color: white;
    border-color: #17a2b8;
}

.btn-info:hover {
    background: #138496;
    border-color: #117a8b;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(23, 162, 184, 0.25);
}

.filter-bar {
    display: flex;
    gap: 15px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.filter-bar input,
.filter-bar select {
    padding: 13px 16px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 15px;
    flex: 1;
    min-width: 200px;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.25s ease;
}

.filter-bar input:focus,
.filter-bar select:focus {
    outline: none;
    border-color: var(--text-primary);
    box-shadow: 0 0 0 3px var(--shadow);
}

.contract-list,
.rates-list,
.merged-list,
.logs-list {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.contract-card,
.rate-card,
.merged-card,
.log-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    transition: all 0.25s ease;
}

.contract-card:hover,
.rate-card:hover,
.merged-card:hover,
.log-card:hover {
    border-color: var(--border-color-strong);
    box-shadow: 0 4px 16px var(--shadow);
    transform: translateY(-2px);
}

.contract-header,
.rate-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 18px;
    flex-wrap: wrap;
    gap: 12px;
}

.contract-title {
    font-size: 1.3em;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
}

.contract-status {
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-active {
    background: #1a1a1a;
    color: white;
}

.status-completed {
    background: #666;
    color: white;
}

.status-overdue {
    background: #dc3545;
    color: white;
}

.contract-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 18px;
    margin-bottom: 18px;
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 400;
}

.detail-value {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: -0.2px;
}

.contract-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    width: 100%;
}

.contract-actions .btn {
    padding: 9px 18px;
    font-size: 14px;
}

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-overlay);
    backdrop-filter: blur(4px);
    transition: background-color 0.3s ease;
}

.modal-content {
    background-color: var(--bg-secondary);
    margin: 5% auto;
    padding: 35px;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 8px 32px var(--shadow-strong);
    position: relative;
    border: 1px solid var(--border-color);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.close {
    color: var(--text-secondary);
    float: right;
    font-size: 28px;
    font-weight: 300;
    cursor: pointer;
    position: absolute;
    right: 22px;
    top: 22px;
    transition: all 0.2s ease;
    line-height: 1;
}

.close:hover {
    color: var(--text-primary);
    transform: scale(1.1);
}

.form-group {
    margin-bottom: 22px;
}

.form-group label {
    display: block;
    margin-bottom: 9px;
    font-weight: 400;
    color: var(--text-primary);
    font-size: 14px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 13px 16px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 15px;
    background: var(--input-bg);
    color: var(--text-primary);
    transition: all 0.25s ease;
    font-family: inherit;
}

.form-group textarea {
    resize: vertical;
    min-height: 60px;
}

.form-group small {
    display: block;
    margin-top: 6px;
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.4;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--text-primary);
    box-shadow: 0 0 0 3px var(--shadow);
}

.form-group input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
}

.form-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    margin-top: 32px;
}

.payment-info {
    background: #f8f8f8;
    padding: 18px;
    border-radius: 10px;
    margin-bottom: 22px;
    border: 1px solid #e8e8e8;
}

.payment-info p {
    margin: 10px 0;
    font-size: 15px;
    color: #000;
    line-height: 1.6;
}

.recent-section {
    margin-top: 45px;
}

.recent-section h2 {
    margin-bottom: 24px;
    color: #000;
    font-weight: 400;
    letter-spacing: -0.5px;
}

/* Dark mode styles for specific elements */
[data-theme="dark"] .empty-state {
    color: var(--text-secondary);
}

.empty-state {
    text-align: center;
    padding: 70px 20px;
    color: #888;
}

.empty-state h3 {
    font-size: 1.5em;
    margin-bottom: 12px;
    color: var(--text-secondary);
    font-weight: 400;
}

.error-message {
    background: #fff5f5;
    color: #dc3545;
    padding: 14px 16px;
    border-radius: 8px;
    margin-bottom: 22px;
    border: 1px solid #fcc;
    font-size: 14px;
    line-height: 1.5;
}

.file-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    margin-top: 6px;
    background: white;
    color: #000;
    transition: all 0.25s ease;
}

.file-input:focus {
    outline: none;
    border-color: #000;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.image-preview {
    margin-top: 12px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.image-preview img {
    max-width: 200px;
    max-height: 150px;
    border: 1px solid #ddd;
    border-radius: 10px;
    object-fit: cover;
    cursor: pointer;
    transition: all 0.25s ease;
}

.image-preview img:hover {
    border-color: #999;
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.image-preview .image-item {
    position: relative;
    display: inline-block;
}

.image-preview .remove-image {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 50%;
    width: 26px;
    height: 26px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(220, 53, 69, 0.3);
}

.image-preview .remove-image:hover {
    background: #c82333;
    transform: scale(1.1);
}

.cccd-images {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 24px;
    margin-top: 18px;
}

.cccd-image-item {
    text-align: center;
}

.cccd-image-item img {
    max-width: 100%;
    max-height: 300px;
    border: 1px solid #ddd;
    border-radius: 10px;
    object-fit: contain;
    cursor: pointer;
    transition: all 0.25s ease;
}

.cccd-image-item img:hover {
    border-color: #999;
    transform: scale(1.01);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.cccd-image-item label {
    display: block;
    margin-top: 10px;
    font-weight: 400;
    color: #666;
    font-size: 14px;
}

.merged-card {
    background: #1a1a1a;
    color: white;
    border-color: rgba(255, 255, 255, 0.1);
}

.merged-card .contract-title {
    color: white;
}

.merged-card .detail-label {
    color: rgba(255, 255, 255, 0.7);
}

.merged-card .detail-value {
    color: white;
}

.merged-contracts {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.merged-contract-item {
    background: rgba(255, 255, 255, 0.08);
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 14px;
    line-height: 1.6;
}

/* Payment History Styles */
.payment-history-summary {
    background: #f8f8f8;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 25px;
    border: 1px solid #e8e8e8;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #e0e0e0;
}

.summary-item:last-child {
    border-bottom: none;
}

.summary-label {
    font-size: 14px;
    color: #666;
    font-weight: 400;
}

.summary-value {
    font-size: 16px;
    font-weight: 500;
    color: #000;
}

.payment-history-items {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.payment-history-item {
    background: white;
    border: 1px solid #e8e8e8;
    border-radius: 10px;
    padding: 18px;
    transition: all 0.25s ease;
}

.payment-history-item:hover {
    border-color: #ccc;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.payment-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 10px;
}

.payment-history-header > div:first-child {
    font-size: 15px;
    color: #333;
}

.payment-history-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
}

.payment-history-details .detail-item {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 0;
}

.payment-history-details .detail-label {
    margin-bottom: 0;
    font-size: 13px;
}

.payment-history-details .detail-value {
    font-size: 15px;
}

@media (max-width: 768px) {
    body {
        padding: 5px;
        overflow-x: hidden;
    }

    .container {
        border-radius: 8px;
        overflow-x: hidden;
    }

    header {
        padding: 12px 10px;
        position: relative; /* Đảm bảo menu dropdown hoạt động đúng */
        z-index: 100; /* Đảm bảo header ở trên các element khác */
    }

    /* Mobile menu toggle hiển thị */
    .mobile-menu-toggle {
        display: flex !important;
    }

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

    /* Ẩn desktop buttons */
    .header-buttons-desktop {
        display: none !important;
    }

    .header-top {
        flex-direction: row;
        align-items: center;
        gap: 10px;
        margin-bottom: 10px;
        position: relative;
    }

    .header-left {
        flex: 1;
        display: flex;
        align-items: center;
        gap: 10px;
    }

    .header-right {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    header h1 {
        font-size: 1.2em;
        margin: 0;
        word-wrap: break-word;
        flex: 1;
    }

    #current-user {
        font-size: 11px;
        display: none; /* Ẩn trên mobile, chỉ hiển thị trong menu */
    }

    #impersonate-badge {
        font-size: 10px;
        padding: 4px 8px;
        margin: 0;
        width: 100%;
        text-align: center;
    }

    /* Mobile user menu */
    .mobile-user-menu {
        position: absolute;
        top: 100%;
        right: 10px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        box-shadow: 0 4px 12px var(--shadow);
        z-index: 1000;
        min-width: 200px;
        margin-top: 5px;
    }

    .mobile-user-menu.show {
        display: flex !important;
    }

    /* Tabs navigation mobile */
    .tabs {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--header-bg);
        padding: 10px;
        gap: 5px;
        z-index: 1001; /* Cao hơn header để hiển thị trên top */
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
        max-height: calc(100vh - 150px);
        overflow-y: auto;
        margin-top: 0;
        border-bottom: 1px solid var(--border-color);
        -webkit-overflow-scrolling: touch; /* Smooth scroll trên iOS */
        scroll-behavior: smooth;
    }

    .tabs.show {
        display: flex !important;
        animation: slideDown 0.3s ease-out;
    }

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

    .tab-btn {
        width: 100%;
        text-align: left;
        padding: 12px 15px;
        font-size: 14px;
        border-radius: 6px;
        margin: 0;
        white-space: nowrap; /* Tránh wrap text */
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 20px;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-number {
        font-size: 1.8em;
    }

    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .section-header h2 {
        font-size: 1.2em;
        margin-bottom: 0;
    }

    .section-header > div {
        width: 100%;
        flex-direction: column;
        gap: 8px;
        align-items: stretch;
    }

    .section-header button {
        width: 100%;
        margin: 0;
    }

    /* Bulk actions toolbar mobile */
    #bulk-actions-toolbar {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    #bulk-actions-toolbar > * {
        width: 100%;
    }

    #bulk-actions-toolbar span {
        text-align: center;
        margin-bottom: 5px;
    }

    /* Contract cards mobile */
    .contract-card {
        padding: 15px;
        margin-bottom: 15px;
    }

    .contract-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .contract-title {
        font-size: 1.1em;
        word-wrap: break-word;
    }

    .contract-details {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .detail-item {
        word-wrap: break-word;
    }

    .detail-value {
        font-size: 14px;
        word-break: break-word;
    }

    .contract-actions {
        flex-direction: column;
        gap: 8px;
    }

    .contract-actions .btn {
        width: 100%;
        margin: 0;
    }
    
    .tab-content {
        padding: 10px;
    }

    .filter-bar {
        flex-direction: column;
        gap: 8px;
    }

    .filter-bar input,
    .filter-bar select {
        width: 100%;
        min-width: auto;
    }

    /* Charts section mobile */
    .charts-section {
        margin-top: 20px;
        margin-bottom: 20px;
    }

    .charts-section > div {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }

    .chart-container {
        padding: 15px !important;
        min-width: 0;
    }

    .chart-container canvas {
        max-width: 100% !important;
        height: auto !important;
    }

    .payment-history-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .payment-history-details {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .modal-content {
        width: 95%;
        padding: 20px 15px;
        margin: 5% auto;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-content h2 {
        font-size: 1.2em;
        margin-bottom: 15px;
        padding-right: 30px;
    }

    .close {
        right: 15px;
        top: 15px;
        font-size: 24px;
    }

    .form-group {
        margin-bottom: 15px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 10px 12px;
        font-size: 14px;
    }

    .form-actions {
        flex-direction: column;
        gap: 8px;
    }

    .form-actions button {
        width: 100%;
    }

    .reminders-dropdown {
        width: calc(100vw - 20px);
        right: 10px;
        left: auto;
        max-width: calc(100vw - 20px);
    }

    .calendar-grid {
        gap: 3px;
    }

    .calendar-grid > div {
        min-height: 50px;
        padding: 4px;
        font-size: 11px;
    }

    .overdue-alert-content {
        width: 95%;
        padding: 15px;
    }

    .overdue-alert-header h2 {
        font-size: 16px;
    }

    .overdue-alert-icon {
        font-size: 40px;
    }

    /* Calendar controls mobile */
    #calendar .section-header > div {
        flex-wrap: wrap;
        width: 100%;
    }

    #calendar .section-header button {
        flex: 1 1 auto;
        min-width: 80px;
        font-size: 11px;
        padding: 8px 10px;
    }

    #calendar-month-year {
        width: 100%;
        margin: 8px 0;
        text-align: center;
        font-size: 14px;
    }

    /* Reports mobile */
    #reports .section-header > div {
        flex-direction: column;
        width: 100%;
    }

    #reports .section-header input[type="date"] {
        width: 100%;
    }

    /* Table responsive */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        font-size: 12px;
    }

    table thead,
    table tbody,
    table tr {
        display: table;
        width: 100%;
        table-layout: fixed;
    }

    /* Stats cards in reports */
    .financial-report .stats-grid {
        grid-template-columns: 1fr;
    }

    /* Customer profile mobile */
    .customer-profile {
        font-size: 13px;
    }

    /* CCCD images mobile */
    .cccd-images {
        grid-template-columns: 1fr !important;
        gap: 15px;
    }

    /* Customer profile modal mobile */
    #customer-profile-modal .modal-content {
        max-height: 95vh;
        overflow-y: auto;
        padding: 15px 10px;
    }

    #customer-profile-modal .customer-profile-detail > div {
        margin-bottom: 15px;
    }

    #customer-profile-modal .cccd-images {
        grid-template-columns: 1fr !important;
    }

    #customer-profile-modal .cccd-images img {
        max-height: 250px !important;
    }

    /* Contract list in profile modal */
    #customer-profile-modal .contract-list {
        max-height: 300px !important;
    }

    #customer-profile-modal .contract-card {
        padding: 12px;
        margin-bottom: 10px;
    }

    #customer-profile-modal .contract-actions {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 5px;
    }

    #customer-profile-modal .contract-actions .btn {
        flex: 1 1 auto;
        min-width: calc(50% - 5px);
        font-size: 11px;
        padding: 6px 8px;
    }

    /* Empty state mobile */
    .empty-state {
        padding: 20px 10px;
    }

    .empty-state h3 {
        font-size: 1.1em;
    }

    /* Merged contracts mobile */
    .merged-contracts {
        margin-top: 15px;
        padding-top: 15px;
    }

    .merged-contract-item {
        padding: 10px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    body {
        padding: 3px;
        overflow-x: hidden;
    }

    header {
        padding: 10px 8px;
    }

    header h1 {
        font-size: 1em;
        margin: 0;
    }

    .mobile-menu-toggle {
        width: 28px;
        height: 28px;
    }

    .mobile-menu-toggle span {
        width: 20px;
        height: 2px;
    }

    .mobile-user-menu-toggle {
        padding: 6px 10px;
        font-size: 16px;
    }

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

    .stat-card {
        padding: 12px;
    }

    .stat-number {
        font-size: 1.5em;
    }

    .stat-card h3 {
        font-size: 11px;
    }

    .section-header h2 {
        font-size: 1.1em;
    }

    .contract-card,
    .rate-card,
    .merged-card,
    .log-card {
        padding: 12px;
    }

    .contract-title {
        font-size: 1em;
    }

    .detail-label {
        font-size: 11px;
    }

    .detail-value {
        font-size: 13px;
    }

    .modal-content {
        padding: 15px 10px;
        width: 98%;
        margin: 2% auto;
    }

    .modal-content h2 {
        font-size: 1.1em;
        margin-bottom: 12px;
    }

    .form-group {
        margin-bottom: 12px;
    }

    .form-group label {
        font-size: 12px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        padding: 8px 10px;
        font-size: 13px;
    }

    .btn {
        padding: 8px 16px;
        font-size: 12px;
    }

    .contract-actions .btn {
        padding: 8px 12px;
        font-size: 12px;
    }

    .tab-content {
        padding: 8px;
    }

    .filter-bar {
        gap: 6px;
    }

    .calendar-grid > div {
        min-height: 40px;
        padding: 3px;
        font-size: 10px;
    }

    /* Calendar upcoming payments list mobile */
    #calendar-container > div:first-child {
        padding: 15px 10px !important;
    }

    #calendar-container > div:first-child h3 {
        font-size: 16px !important;
        margin-bottom: 12px !important;
    }

    #calendar-container > div:first-child > div {
        max-height: 300px !important;
    }

    #calendar-container > div:first-child > div > div {
        padding: 12px !important;
        margin-bottom: 10px !important;
    }

    #calendar-container > div:first-child > div > div > div:first-child {
        flex-direction: column !important;
        gap: 8px !important;
    }

    #calendar-container > div:first-child > div > div > div:first-child > div:first-child {
        width: 100% !important;
    }

    #calendar-container > div:first-child > div > div > div:first-child > div:last-child {
        width: 100% !important;
        text-align: left !important;
        margin-left: 0 !important;
    }

    #calendar-container > div:first-child > div > div > div:last-child {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    .chart-container {
        padding: 10px !important;
    }

    .chart-container h3 {
        font-size: 14px;
        margin-bottom: 10px;
    }

    /* Payment modal mobile */
    .payment-info {
        font-size: 13px;
    }

    /* Reminders mobile */
    .reminders-dropdown {
        width: calc(100vw - 10px);
        right: 5px;
    }

    .reminder-item {
        padding: 10px;
        font-size: 12px;
    }

    /* API Docs mobile */
    #api-docs .tab-content {
        padding: 15px 10px;
    }

    #api-docs .tab-content > div {
        padding: 15px 10px;
    }

    #api-docs .tab-content ul {
        font-size: 13px;
        padding-left: 20px;
    }
}

/* Activity Log Styles */
.log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 10px;
}

.log-content {
    color: #333;
    line-height: 1.6;
}

.log-action-badge {
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Debt Reminders Styles */
.reminders-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 32px var(--shadow-strong);
    width: 400px;
    max-height: 600px;
    z-index: 1000;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.reminders-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-tertiary);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.reminders-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
}

.reminders-list {
    max-height: 450px;
    overflow-y: auto;
    padding: 10px;
}

.reminder-item {
    padding: 12px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.reminder-item:hover {
    border-color: var(--border-color-strong);
    box-shadow: 0 2px 8px var(--shadow);
}

.reminder-item.unread {
    background: var(--bg-tertiary);
    border-left: 4px solid #dc3545;
}

[data-theme="dark"] .reminder-item.unread {
    background: rgba(220, 53, 69, 0.1);
}

.reminder-item.overdue {
    background: var(--bg-tertiary);
    border-left: 4px solid #dc3545;
}

[data-theme="dark"] .reminder-item.overdue {
    background: rgba(220, 53, 69, 0.1);
}

.reminder-item.due-soon {
    background: var(--bg-tertiary);
    border-left: 4px solid #ffc107;
}

[data-theme="dark"] .reminder-item.due-soon {
    background: rgba(255, 193, 7, 0.1);
}

.reminder-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 8px;
}

.reminder-title {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 14px;
    flex: 1;
}

.reminder-type-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    margin-left: 8px;
}

.reminder-type-badge.overdue {
    background: #dc3545;
    color: white;
}

.reminder-type-badge.due-soon {
    background: #ffc107;
    color: #333;
}

.reminder-type-badge.manual {
    background: #17a2b8;
    color: white;
}

.reminder-message {
    color: #666;
    font-size: 13px;
    line-height: 1.5;
    margin-bottom: 8px;
}

.reminder-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: #999;
}

.reminder-actions {
    display: flex;
    gap: 8px;
}

.reminder-actions button {
    padding: 4px 8px;
    font-size: 11px;
    border-radius: 4px;
}

.reminders-footer {
    padding: 10px 15px;
    border-top: 1px solid #e8e8e8;
    background: #f8f8f8;
    text-align: center;
}

.empty-reminders {
    padding: 40px 20px;
    text-align: center;
    color: #999;
}

.empty-reminders p {
    margin: 0;
    font-size: 14px;
}

/* Overdue Alert Popup Styles */
.overdue-alert-modal {
    z-index: 2000;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(6px);
}

.overdue-alert-content {
    max-width: 700px;
    background: linear-gradient(135deg, #fff5f5 0%, #ffffff 100%);
    border: 2px solid #dc3545;
    box-shadow: 0 12px 48px rgba(220, 53, 69, 0.3);
    animation: slideDown 0.3s ease-out;
}

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

.overdue-alert-header {
    text-align: center;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 2px solid #dc3545;
}

.overdue-alert-icon {
    font-size: 64px;
    margin-bottom: 15px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.overdue-alert-header h2 {
    color: #dc3545;
    font-size: 24px;
    font-weight: 600;
    margin: 0;
}

.overdue-alert-body {
    margin-bottom: 25px;
}

.overdue-alert-list {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 15px;
}

.overdue-alert-item {
    background: white;
    border: 1px solid #fcc;
    border-left: 4px solid #dc3545;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 12px;
    transition: all 0.2s ease;
}

.overdue-alert-item:hover {
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.15);
    transform: translateX(4px);
}

.overdue-alert-item-title {
    font-weight: 600;
    color: #dc3545;
    font-size: 15px;
    margin-bottom: 8px;
}

.overdue-alert-item-details {
    font-size: 13px;
    color: #666;
    line-height: 1.6;
}

.overdue-alert-item-details strong {
    color: #333;
}

/* Calendar Grid Styles */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px;
    margin-top: 20px;
}

.calendar-day {
    padding: 8px;
    min-height: 80px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-secondary);
    transition: all 0.2s ease;
}

.calendar-day:hover {
    border-color: var(--border-color-strong);
    box-shadow: 0 2px 8px var(--shadow);
}

.calendar-day.has-events {
    background: var(--bg-tertiary);
}

[data-theme="dark"] .calendar-day.has-events {
    background: rgba(220, 53, 69, 0.1);
}

.calendar-day-number {
    font-weight: bold;
    margin-bottom: 5px;
    color: var(--text-primary);
}

.calendar-event {
    font-size: 11px;
    padding: 3px 5px;
    margin-bottom: 3px;
    border-radius: 3px;
    cursor: pointer;
    color: white;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.calendar-event.overdue {
    background: #dc3545;
}

.calendar-event.due-soon {
    background: #ffc107;
    color: #333;
}

.calendar-event.upcoming {
    background: #17a2b8;
}

/* Financial Report Table */
.financial-report table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.financial-report table thead tr {
    background: #1a1a1a;
    color: white;
}

.financial-report table th {
    padding: 12px;
    text-align: left;
    font-weight: 500;
}

.financial-report table td {
    padding: 10px 12px;
    border-bottom: 1px solid #e0e0e0;
}

.financial-report table tbody tr:hover {
    background: #f8f8f8;
}

.financial-report table tbody tr:last-child td {
    border-bottom: none;
}

/* Loading Spinner */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Smooth transitions */
* {
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* Print styles */
@media print {
    header,
    .tabs,
    .btn,
    .filter-bar {
        display: none !important;
    }

    .tab-content {
        display: block !important;
        padding: 0;
    }

    .contract-card,
    .rate-card {
        page-break-inside: avoid;
        margin-bottom: 20px;
    }
}
