:root {
    --primary-color: #25d366;
    --primary: var(--primary-color);
    --primary-dark: #20ba5a;
    --primary-light: #d9fdd3;
    --secondary-color: #54656f;
    --accent-color: #00a884;

    --success: #22c55e;
    --success-color: var(--success);
    --danger: #ef4444;
    --danger-color: var(--danger);
    --warning: #f59e0b;
    --info-color: #3b82f6;

    --bg-color: #f0f2f5;
    --bg-secondary: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #111b21;
    --text-secondary: #667781;
    --text-dark: #1e293b;
    --border-color: #e9edef;
    --hover-bg: #f5f6f6;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);

    --sidebar-width: 220px;
    --topbar-height: 52px;
}

.text-success {
    color: var(--success) !important;
}

.text-danger {
    color: var(--danger) !important;
}

.text-warning {
    color: var(--warning) !important;
}

.text-info {
    color: var(--info-color) !important;
}

[data-theme='dark'] .text-success {
    color: var(--success-color) !important;
}

[data-theme='dark'] .text-danger {
    color: var(--danger-color) !important;
}

[data-theme='dark'] .text-info {
    color: var(--info-color) !important;
}

[data-theme='dark'] {
    --bg-color: #0b141a;
    --bg-secondary: #182229;
    --card-bg: #111b21;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --text-dark: #d1d7db;
    --border-color: #222d34;
    --hover-bg: #202c33;
    --primary-light: rgba(37, 211, 102, 0.15);
    --primary-dark: #25d366;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5);

    --success-color: #7ee0a4;
    --danger-color: #fb9292;
    --info-color: #8ab4f8;

    --status-pending-bg: #322d1a;
    --status-pending-text: #ffe08a;
    --status-approved-bg: #1c2e23;
    --status-approved-text: #7ee0a4;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.4;
    font-size: 14px;
}

/* App Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--card-bg);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    transition: transform 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.logo {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    text-decoration: none;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: var(--primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    font-size: 1rem;
}

.sidebar-menu {
    padding: 0.5rem 0;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: background 0.2s;
    font-size: 0.9375rem;
}

.menu-item:hover {
    background: var(--hover-bg);
}

.menu-item.active {
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 500;
}

.menu-icon {
    font-size: 1.125rem;
    width: 20px;
    text-align: center;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
}

/* Topbar */
.topbar {
    height: var(--topbar-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 90;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.25rem;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.375rem;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.page-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box input {
    padding: 0.375rem 0.75rem 0.375rem 2rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    width: 240px;
    font-size: 0.875rem;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.search-icon {
    position: absolute;
    left: 0.625rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Content Area */
.content-wrapper {
    flex: 1;
    padding: 1rem;
}

.content-header {
    margin-bottom: 1rem;
}

.content-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.content-subtitle {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Cards */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
}

.card-header {
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
}

.card-body {
    padding: 1rem;
}

/* Grid */
.grid {
    display: grid;
    gap: 0.75rem;
}

.grid-cols-1 {
    grid-template-columns: repeat(1, 1fr);
}

.grid-cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
}

.grid-cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

/* Customer Cards - Compact WhatsApp Style */
.customer-card {
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: 0;
}

.customer-card:hover {
    background: var(--hover-bg);
}

.customer-card:not(:last-child) {
    border-bottom: 1px solid var(--border-color);
}

.customer-info {
    margin-bottom: 0.5rem;
}

.customer-name {
    font-size: 0.9375rem;
    font-weight: 500;
    margin-bottom: 0.125rem;
    color: var(--text-primary);
}

.customer-mobile {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.customer-actions {
    display: flex;
    gap: 0.25rem;
}

.balance-section {
    padding-top: 0.5rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.balance-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.balance-amount {
    font-size: 1rem;
    font-weight: 600;
}

.balance-positive {
    color: var(--danger);
}

.balance-negative {
    color: var(--success);
}

.balance-zero {
    color: var(--text-secondary);
}

/* Buttons */
.btn {
    padding: 0.5rem 0.875rem;
    border-radius: 6px;
    border: none;
    font-weight: 500;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    text-decoration: none;
    font-family: inherit;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-secondary {
    background: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #16a34a;
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: 0.375rem 0.625rem;
    font-size: 0.8125rem;
}

.btn-icon {
    padding: 0.375rem;
    border-radius: 50%;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background: var(--hover-bg);
    color: var(--primary-color);
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-label {
    display: block;
    margin-bottom: 0.375rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.9375rem;
    font-family: inherit;
    transition: all 0.2s;
    background: var(--card-bg);
    color: var(--text-primary);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.1);
}

textarea.form-control {
    resize: vertical;
}

.form-help {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.2s;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal {
    background: var(--card-bg);
    border-radius: 8px;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    transform: scale(0.95);
    transition: transform 0.2s;
}

.modal-overlay.active .modal {
    transform: scale(1);
}

.modal-header {
    padding: 1rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close-modal:hover {
    background: var(--hover-bg);
}

.modal-body {
    padding: 1rem;
}

/* Transaction List - Compact */
.transaction-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
}

.transaction-item:last-child {
    border-bottom: none;
}

.transaction-info {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.transaction-desc {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.9375rem;
}

.transaction-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.transaction-badge {
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-credit {
    background: #fee2e2;
    color: #991b1b;
}

.badge-debit {
    background: #dcfce7;
    color: #166534;
}

.transaction-amount {
    font-size: 0.9375rem;
    font-weight: 600;
}

.amount-credit {
    color: var(--danger);
}

.amount-debit {
    color: var(--success);
}

/* Stats Cards - Compact */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.875rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Footer - Compact */
.footer {
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    margin-top: auto;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.footer-text {
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.footer-links {
    display: flex;
    gap: 1rem;
}

.footer-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.8125rem;
    transition: color 0.2s;
}

.footer-link:hover {
    color: var(--primary-color);
}

/* Utilities */
.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.gap-1 {
    gap: 0.5rem;
}

.gap-2 {
    gap: 0.75rem;
}

.gap-3 {
    gap: 1rem;
}

.mb-2 {
    margin-bottom: 0.75rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.text-center {
    text-align: center;
}

.text-primary {
    color: var(--primary-color);
}

.text-secondary {
    color: var(--text-secondary);
}

.text-danger {
    color: var(--danger);
}

.text-success {
    color: var(--success);
}

/* Loading */
.loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.spinner {
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 0.75rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* List-style layout for customers */
.customer-list {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

/* Responsive */
@media (max-width: 1024px) {
    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }

    .grid-cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* =====================================================
   MOBILE ANDROID APP-LIKE DESIGN
   ===================================================== */
@media (max-width: 768px) {
    /* Prevent horizontal scroll globally */
    html, body {
        overflow-x: hidden !important;
        width: 100%;
        max-width: 100vw;
    }
    
    :root {
        --sidebar-width: 280px;
        --topbar-height: 56px;
    }

    /* App Container - Android-like structure */
    .app-container {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Sidebar - Android drawer style */
    .sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.25);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    /* Main Content */
    .main-content {
        margin-left: 0;
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Topbar - Android app bar style */
    .topbar {
        height: var(--topbar-height);
        padding: 0 0.5rem;
        position: sticky;
        top: 0;
        z-index: 90;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    }

    .topbar-left {
        flex: 1;
        min-width: 0;
    }

    .topbar-right {
        flex-shrink: 0;
        gap: 0.375rem;
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        font-size: 1.5rem;
        border-radius: 50%;
        margin-right: 0.25rem;
    }

    .mobile-menu-btn:active {
        background: var(--hover-bg);
    }

    .page-title {
        font-size: 1.125rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Hide search on mobile - use icon instead if needed */
    .search-box {
        display: none;
    }

    /* Buttons - larger touch targets */
    .btn {
        min-height: 44px;
        padding: 0.625rem 1rem;
        font-size: 0.9375rem;
    }

    .btn-sm {
        min-height: 40px;
        padding: 0.5rem 0.875rem;
        font-size: 0.875rem;
    }

    .btn-icon {
        width: 40px;
        height: 40px;
        font-size: 1.125rem;
    }

    /* Content Wrapper */
    .content-wrapper {
        padding: 0.75rem;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }

    .content-title {
        font-size: 1.125rem;
    }

    /* Stats Grid - Android cards style, horizontal scroll */
    .stats-grid {
        display: flex;
        gap: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        padding-bottom: 0.25rem;
        margin: 0 -0.75rem;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .stats-grid::-webkit-scrollbar {
        display: none;
    }

    .stat-card {
        flex: 0 0 auto;
        min-width: 100px;
        padding: 0.75rem;
    }

    /* Grid adjustments */
    .grid-cols-4,
    .grid-cols-3,
    .grid-cols-2 {
        grid-template-columns: 1fr;
    }

    /* Cards - Full width, no border-radius on edges */
    .card {
        border-radius: 12px;
        margin-left: 0;
        margin-right: 0;
    }

    .card-body {
        padding: 0.875rem;
    }

    /* Filter buttons - Horizontal scroll with snap */
    .card-body[style*="overflow-x"] {
        margin: 0 -0.75rem;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .card-body[style*="overflow-x"]::-webkit-scrollbar {
        display: none;
    }

    .card-body .flex.items-center.gap-2 {
        gap: 0.5rem;
    }

    .card-body .flex.items-center.gap-2 .btn {
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* Transaction items */
    .transaction-item {
        grid-template-columns: 1fr;
        gap: 0.5rem;
        padding: 0.875rem;
    }

    /* Footer - Android style bottom bar */
    .footer {
        padding: 0.625rem 0.75rem;
    }

    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 0.5rem;
    }

    .footer-text {
        font-size: 0.75rem;
    }

    /* =====================================================
       MODAL - FULL SCREEN ANDROID STYLE
       ===================================================== */
    .modal-overlay {
        padding: 0;
        align-items: flex-end;
        background: rgba(0, 0, 0, 0.5);
    }

    .modal {
        width: 100% !important;
        max-width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
        margin: 0;
        display: flex;
        flex-direction: column;
        animation: slideUp 0.3s ease;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }

    .modal-overlay.active .modal {
        transform: translateY(0);
    }

    .modal-header {
        padding: 1rem;
        position: sticky;
        top: 0;
        background: var(--card-bg);
        z-index: 10;
        border-bottom: 1px solid var(--border-color);
        min-height: 56px;
        display: flex;
        align-items: center;
    }

    .modal-title {
        font-size: 1.25rem;
        font-weight: 600;
    }

    .close-modal {
        width: 40px;
        height: 40px;
        font-size: 1.75rem;
    }

    .modal-body {
        flex: 1;
        padding: 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Form controls - larger for touch */
    .form-group {
        margin-bottom: 1.25rem;
    }

    .form-label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
        font-weight: 500;
    }

    .form-control {
        min-height: 48px;
        padding: 0.75rem 1rem;
        font-size: 1rem;
        border-radius: 8px;
    }

    textarea.form-control {
        min-height: 80px;
    }

    select.form-control {
        appearance: none;
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
        background-position: right 0.75rem center;
        background-repeat: no-repeat;
        background-size: 1.25em;
        padding-right: 2.5rem;
    }

    /* Lead/Task Cards - Clean mobile design */
    .lead-card,
    .task-card {
        padding: 1rem;
        margin-bottom: 0.5rem;
        border-radius: 12px;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    }

    .lead-card:active,
    .task-card:active {
        background: var(--hover-bg);
    }

    /* Customer list for mobile */
    .customer-list {
        border-radius: 12px;
    }

    .customer-card {
        padding: 1rem;
        min-height: 60px;
    }

    .customer-name {
        font-size: 1rem;
    }

    /* Report modal specific */
    .report-filters {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 0.875rem !important;
        padding: 1rem !important;
        margin: 0 -1rem !important;
        width: calc(100% + 2rem) !important;
    }

    #reportResults {
        border-radius: 8px;
        margin: 0 -1rem;
        width: calc(100% + 2rem);
    }

    #reportResults table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        font-size: 0.8rem;
    }

    #reportResults th,
    #reportResults td {
        padding: 0.5rem 0.625rem !important;
        white-space: nowrap;
    }

    /* Status and Priority badges - mobile size */
    .status-badge,
    .priority-badge {
        font-size: 0.6875rem;
        padding: 0.25rem 0.5rem;
    }

    /* Flex utilities for mobile */
    .flex.gap-2 {
        gap: 0.5rem;
    }

    /* Action buttons in cards */
    .btn-icon {
        background: var(--bg-secondary);
        border-radius: 8px;
    }
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

@media (min-width: 769px) {
    .sidebar-overlay {
        display: none !important;
    }
}

/* Profile Avatar Compact */
.profile-avatar {
    width: 64px;
    height: 64px;
    margin: 0 auto 0.75rem;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.75rem;
    font-weight: 700;
}