/* =========================================
   1. VARIABLES & RESET
   ========================================= */
:root {
    --primary: #2563EB;     /* Blue - Main Action */
    --secondary: #EC4899;   /* Pink - Highlights */
    --accent: #10B981;      /* Green - Success */
    --danger: #EF4444;      /* Red - Delete/Cancel */
    --dark: #111827;        /* Black - Text/Headings */
    --light: #F9FAFB;       /* Light Grey - Background */
    --white: #ffffff;
    --gray: #6B7280;
    --border: #E5E7EB;
    --shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.emi-app * { 
    box-sizing: border-box; 
    font-family: 'Poppins', sans-serif;
}

/* Main Container (App Wrapper) */
.emi-app {
    max-width: 500px; 
    margin: 30px auto;
    background: var(--light); 
    border-radius: 24px;
    overflow: hidden; 
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border); 
    position: relative; 
    min-height: 750px;
    /* Smooth Scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--gray) transparent;
}

/* =========================================
   2. HEADER SECTION
   ========================================= */
.emi-head {
    background: linear-gradient(135deg, var(--dark), #1f2937); 
    color: var(--white);
    padding: 30px 25px; 
    border-bottom-left-radius: 30px; 
    border-bottom-right-radius: 30px;
    position: relative; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.15); 
    z-index: 10;
}

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

.emi-head-top span {
    font-size: 14px;
    opacity: 0.9;
    font-weight: 500;
}

.emi-logout-btn { 
    background: rgba(255,255,255,0.15); 
    border: 1px solid rgba(255,255,255,0.2); 
    color: var(--white); 
    padding: 6px 14px; 
    border-radius: 20px; 
    font-size: 11px; 
    cursor: pointer; 
    transition: 0.3s;
    backdrop-filter: blur(5px);
}
.emi-logout-btn:hover {
    background: var(--danger);
    border-color: var(--danger);
}

.emi-balance-info { text-align: center; }
.emi-balance-info small { 
    text-transform: uppercase; 
    letter-spacing: 1px; 
    font-size: 10px; 
    opacity: 0.7; 
}
.emi-balance-info h1 { 
    font-size: 2.5rem; 
    margin: 5px 0; 
    font-weight: 700; 
    /* Gradient Text */
    background: linear-gradient(to right, #60A5FA, #A78BFA); 
    -webkit-background-clip: text; 
    -webkit-text-fill-color: transparent; 
}

/* =========================================
   3. NAVIGATION TABS
   ========================================= */
.emi-tabs { 
    display: flex; 
    background: var(--white); 
    padding: 10px; 
    margin: -30px 20px 20px; 
    border-radius: 16px; 
    box-shadow: var(--shadow); 
    position: relative; 
    z-index: 20; 
    overflow-x: auto; 
    gap: 8px;
    justify-content: space-between;
}

.emi-tab { 
    flex: 1; 
    padding: 12px 10px; 
    border: none; 
    background: transparent; 
    font-weight: 600; 
    font-size: 12px; 
    color: var(--gray); 
    border-radius: 12px; 
    cursor: pointer; 
    white-space: nowrap; 
    transition: all 0.3s ease;
    text-align: center;
}

.emi-tab:hover { background: #F3F4F6; }

.emi-tab.active { 
    background: var(--primary); 
    color: var(--white); 
    box-shadow: 0 4px 12px rgba(37,99,235,0.3); 
}

/* =========================================
   4. CONTENT & FORMS
   ========================================= */
.emi-content { 
    display: none; 
    padding: 10px 25px 80px; 
    animation: fadeIn 0.4s ease; 
}
.emi-content.active { display: block; }

.emi-inp { 
    width: 100%; 
    padding: 14px 16px; 
    border: 1px solid var(--border); 
    border-radius: 12px; 
    font-size: 14px; 
    margin-bottom: 15px; 
    outline: none; 
    background: var(--white);
    transition: 0.3s;
}
.emi-inp:focus { 
    border-color: var(--primary); 
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); 
}

label { 
    display: block; 
    font-size: 12px; 
    font-weight: 600; 
    color: #4B5563; 
    margin-bottom: 6px; 
    margin-left: 2px;
}

textarea.emi-inp { resize: vertical; min-height: 80px; }

/* Search Box Container */
.search-box {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    background: var(--white);
    padding: 5px;
    border-radius: 14px;
    border: 1px solid var(--border);
}
.search-box input {
    border: none;
    margin: 0;
    box-shadow: none;
}
.search-box button {
    width: auto;
    padding: 8px 16px;
    border-radius: 10px;
}

/* =========================================
   5. BUTTONS
   ========================================= */
.emi-btn { 
    width: 100%; 
    padding: 14px; 
    border: none; 
    border-radius: 12px; 
    font-weight: 600; 
    font-size: 14px; 
    cursor: pointer; 
    color: var(--white); 
    display: inline-flex; 
    justify-content: center; 
    align-items: center; 
    gap: 8px;
    transition: transform 0.1s, filter 0.2s;
}
.emi-btn:active { transform: scale(0.98); }
.emi-btn:disabled { opacity: 0.7; cursor: not-allowed; }

.btn-p { 
    background: linear-gradient(135deg, var(--primary), #3B82F6); 
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.3);
}
.btn-s { 
    background: linear-gradient(135deg, var(--accent), #34D399); 
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}
.btn-d { 
    background: linear-gradient(135deg, var(--danger), #F87171); 
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

/* =========================================
   6. PRODUCT LIST (Responsive Grid)
   ========================================= */
#prod-list, #mp-list, #wp-list { 
    display: grid; 
    grid-template-columns: 1fr; 
    gap: 20px; 
}
@media (min-width: 400px) { 
    #prod-list, #mp-list { grid-template-columns: 1fr 1fr; } 
}

.emi-card { 
    background: var(--white); 
    border-radius: 16px; 
    padding: 12px; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.03); 
    border: 1px solid #F3F4F6; 
    display: flex; 
    flex-direction: column; 
    transition: transform 0.2s;
}
.emi-card:hover { transform: translateY(-3px); }

.emi-slider { 
    display: flex; 
    overflow-x: auto; 
    gap: 10px; 
    padding-bottom: 12px; 
    scroll-behavior: smooth;
    -ms-overflow-style: none;  
    scrollbar-width: none;  
}
.emi-slider::-webkit-scrollbar { display: none; }

.emi-slider img { 
    width: 100%; 
    height: 150px; 
    object-fit: cover; 
    border-radius: 12px; 
    flex-shrink: 0; 
    background: #f0f0f0; 
}

.emi-card-body { 
    padding-top: 5px; 
    display: flex; 
    flex-direction: column; 
    flex-grow: 1; 
}

/* CRITICAL FIX: Word Break for Long Names */
.emi-card h4, 
.w-list-item span, 
.mo-item div, 
.emi-table td,
#bf-prod-name { 
    margin: 0 0 5px; 
    font-size: 14px; 
    color: var(--dark); 
    white-space: normal !important;
    word-break: break-word !important; 
    overflow-wrap: anywhere !important;
    line-height: 1.4;
}

.emi-price { 
    font-size: 16px; 
    font-weight: 700; 
    color: var(--primary); 
    display: block; 
    margin-bottom: 10px; 
}

/* =========================================
   7. TABLES & LISTS (History & Admin)
   ========================================= */
.emi-table { 
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 0;
    background: var(--white); 
    border-radius: 12px; 
    overflow: hidden; 
    font-size: 13px; 
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
    table-layout: fixed; /* Ensures text wrap works */
}

.emi-table th { 
    background: #F8FAFC; 
    padding: 12px 15px; 
    text-align: left; 
    font-weight: 600; 
    color: var(--gray);
    border-bottom: 1px solid var(--border);
}

.emi-table td { 
    padding: 12px 15px; 
    border-bottom: 1px solid #F3F4F6; 
    vertical-align: top;
    color: var(--dark);
}
.emi-table tr:last-child td { border-bottom: none; }

/* Column Width Control */
.emi-table th:first-child { width: 30%; } /* Date */
.emi-table th:nth-child(2) { width: 45%; } /* Item */
.emi-table th:last-child { width: 25%; text-align: right; } /* Amount */

/* Status Badges */
.st-badge { 
    padding: 4px 8px; 
    border-radius: 20px; 
    font-size: 10px; 
    font-weight: 700; 
    text-transform: uppercase; 
    display: inline-block; 
    margin-top: 4px;
    letter-spacing: 0.5px;
}
.st-pending { background: #FEF3C7; color: #D97706; }
.st-accept, .st-confirmed { background: #DBEAFE; color: #2563EB; }
.st-delivery, .st-delivered { background: #D1FAE5; color: #059669; }
.st-rejected, .st-cancelled { background: #FEE2E2; color: #DC2626; }

/* Worker/Merchant List Items */
.w-section { 
    background: var(--white); 
    padding: 20px; 
    border-radius: 16px; 
    margin-bottom: 20px; 
    border: 1px solid #F3F4F6; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.02);
}

.w-list-item { 
    display: flex; 
    justify-content: space-between; 
    align-items: flex-start; /* Better for multiline text */
    padding: 15px; 
    border-bottom: 1px solid #eee; 
    gap: 15px; 
    background: var(--white);
    border-radius: 12px;
    margin-bottom: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.w-list-item:last-child { margin-bottom: 0; }

.w-list-item > span, .w-list-item > div:first-child { 
    flex: 1; 
    font-weight: 500;
} 
.w-list-item > div:last-child { 
    flex-shrink: 0; 
    display: flex;
    gap: 5px;
}

/* =========================================
   8. MODALS & OVERLAYS
   ========================================= */
.emi-modal { 
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(0, 0, 0, 0.6); 
    z-index: 9999; 
    display: none; 
    align-items: center; 
    justify-content: center; 
    backdrop-filter: blur(5px); 
    padding: 20px;
}

.emi-box { 
    background: var(--white); 
    width: 100%; 
    max-width: 420px; 
    padding: 30px; 
    border-radius: 24px; 
    animation: zoomIn 0.2s ease-out; 
    text-align: center; 
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-height: 90vh;
    overflow-y: auto;
}

/* Checkout Modal Summary */
.bf-summary { 
    background: #F0F9FF; 
    padding: 15px; 
    border-radius: 12px; 
    margin: 20px 0; 
    text-align: center; 
    border: 1px dashed #BAE6FD; 
}

/* =========================================
   9. ANIMATIONS
   ========================================= */
@keyframes fadeIn { 
    from { opacity: 0; transform: translateY(10px); } 
    to { opacity: 1; transform: translateY(0); } 
}
@keyframes zoomIn { 
    from { transform: scale(0.95); opacity: 0; } 
    to { transform: scale(1); opacity: 1; } 
}