/* --- Global Styles & Variables --- */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --secondary-color: #10b981;
    --secondary-hover: #059669;
    --secondary-light: #d1fae5;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --danger-light: #fee2e2;
    --warning-color: #f59e0b;
    --warning-light: #fef3c7;
    --bg-main: #f8fafc;
    --bg-card: #ffffff;
    --text-dark: #0f172a;
    --text-light: #475569;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --border-radius: 0.875rem;
    --border-radius-lg: 1.25rem;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body {
    font-family: 'Inter', 'Poppins', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    color: var(--text-dark);
    margin: 0;
    padding: 0.875rem;
    font-size: 15px;
    padding-bottom: 90px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Layout Containers (Mobile-First) --- */
.portal-container {
    max-width: 1400px;
    margin: auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    align-items: start;
}

.form-column, .data-column {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.card {
    background: var(--bg-card);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    opacity: 0;
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

.card:hover::before {
    opacity: 1;
}

.card h2 {
    font-size: 1.5rem;
    margin: 0 0 1.5rem 0;
    color: var(--text-dark);
    font-weight: 700;
    letter-spacing: -0.025em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card h3 {
    font-size: 1.125rem;
    margin: 1.5rem 0 1rem 0;
    color: var(--primary-color);
    font-weight: 600;
    border-bottom: 2px solid var(--primary-light);
    padding-bottom: 0.5rem;
    letter-spacing: -0.015em;
}

/* --- Forms & Inputs --- */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-dark);
    letter-spacing: 0.01em;
}

input[type="text"], 
input[type="tel"], 
input[type="password"], 
input[type="number"], 
input[type="date"], 
select {
    width: 100%;
    padding: 0.875rem 1rem;
    border: 2px solid var(--border-color);
    border-radius: 0.625rem;
    box-sizing: border-box;
    transition: var(--transition);
    background-color: var(--bg-card);
    font-size: 0.9375rem;
    color: var(--text-dark);
    font-family: inherit;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px var(--primary-light);
    background-color: white;
    transform: translateY(-1px);
}

input::placeholder {
    color: var(--text-muted);
}

/* --- Enhanced Buttons --- */
.btn {
    padding: 0.875rem 1.75rem;
    border: none;
    border-radius: 0.625rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9375rem;
    position: relative;
    overflow: hidden;
    letter-spacing: 0.015em;
}

.btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.btn:active::before {
    width: 300px;
    height: 300px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn:active {
    transform: translateY(0);
}

.form-actions .btn {
    width: 100%;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, #4f46e5 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, var(--primary-hover) 0%, #4338ca 100%);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, var(--secondary-color) 0%, #059669 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, var(--secondary-hover) 0%, #047857 100%);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, var(--danger-color) 0%, #dc2626 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: linear-gradient(135deg, var(--danger-hover) 0%, #b91c1c 100%);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.btn-light {
    background-color: var(--bg-card);
    color: var(--text-light);
    border: 2px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

.btn-light:hover {
    background-color: var(--bg-main);
    border-color: var(--text-muted);
}

.form-actions {
    display: flex;
    gap: 0.875rem;
    margin-top: 1.5rem;
    flex-wrap: wrap;
    flex-direction: column;
}

/* --- Product Tiles --- */
#productTilesContainer {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.875rem;
}

.product-tile {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    border: 2px solid var(--border-color);
    border-radius: 0.875rem;
    padding: 0.875rem 0.5rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.product-tile::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.1), transparent);
    transition: left 0.5s;
}

.product-tile:hover::after {
    left: 100%;
}

.product-tile:hover {
    border-color: var(--primary-color);
    background: var(--primary-light);
    transform: scale(1.08);
    box-shadow: var(--shadow-lg);
}

.product-tile .tile-name {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-dark);
    margin-bottom: 0.25rem;
}

.product-tile .tile-price {
    font-size: 0.8125rem;
    color: var(--primary-color);
    font-weight: 600;
}

/* --- Order Items --- */
#currentOrderItems .order-item {
    display: grid;
    grid-template-columns: 1fr 60px 80px 30px;
    gap: 0.875rem;
    align-items: center;
    padding: 0.875rem;
    border-bottom: 1px solid var(--border-color);
    border-radius: 0.5rem;
    transition: var(--transition);
}

#currentOrderItems .order-item:hover {
    background-color: var(--primary-light);
}

#currentOrderItems .order-item input {
    padding: 0.625rem;
    font-size: 0.9375rem;
    border-radius: 0.5rem;
    border: 2px solid var(--border-color);
}

#currentOrderItems .order-item .remove-item-btn {
    background: none;
    border: none;
    color: var(--danger-color);
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    transition: var(--transition);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#currentOrderItems .order-item .remove-item-btn:hover {
    background-color: var(--danger-light);
    transform: rotate(90deg) scale(1.2);
}

/* --- Enhanced Navigation Bar --- */
.main-content {
    max-width: 1400px;
    margin: auto;
}

.view-page {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.view-page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.nav-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
    z-index: 100;
    border-top: 1px solid var(--border-color);
    padding: 0.5rem 0;
}

.nav-btn {
    flex-grow: 1;
    padding: 0.625rem 0.5rem;
    background: none;
    border: none;
    border-top: 3px solid transparent;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    transition: var(--transition);
    width: auto;
    position: relative;
}

.nav-btn svg {
    width: 24px;
    height: 24px;
    stroke-width: 2;
    transition: var(--transition);
}

.nav-btn:active {
    transform: scale(0.95);
}

.nav-btn.active {
    color: var(--primary-color);
    border-top-color: var(--primary-color);
}

.nav-btn.active svg {
    transform: translateY(-2px);
}

/* --- Order Cards --- */
.filter-controls {
    display: flex;
    gap: 0.875rem;
    margin-bottom: 1.25rem;
    flex-direction: column;
}

.order-card {
    background: var(--bg-card);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    border: 2px solid transparent;
    transition: var(--transition);
    margin-bottom: 1.25rem;
    position: relative;
    overflow: hidden;
}

.order-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(180deg, var(--primary-color), var(--secondary-color));
    opacity: 0;
    transition: var(--transition);
}

.order-card:hover {
    box-shadow: var(--shadow-xl);
    transform: translateY(-3px);
    border-color: var(--primary-light);
}

.order-card:hover::before {
    opacity: 1;
}

.order-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    margin-bottom: 1rem;
    font-size: 1.0625rem;
}

.status-badge {
    padding: 0.375rem 0.875rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.025em;
    text-transform: uppercase;
    box-shadow: var(--shadow-sm);
}

.status-badge.Pending {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    color: #92400e;
}

.status-badge.Paid {
    background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
    color: #065f46;
}

.order-card-body p {
    margin: 0.5rem 0;
    color: var(--text-light);
    font-size: 0.9375rem;
}

.order-card-body strong {
    color: var(--text-dark);
    font-weight: 600;
}

.order-card-actions {
    margin-top: 1.25rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.625rem;
}

.collected-quantities {
    background: linear-gradient(135deg, var(--primary-light) 0%, #ddd6fe 100%);
    border-left: 4px solid var(--primary-color);
    padding: 0.875rem;
    margin: 0.75rem 0;
    font-size: 0.9375rem;
    border-radius: 0.625rem;
    box-shadow: var(--shadow-sm);
}

.warning-text {
    padding: 1rem;
    background: linear-gradient(135deg, var(--warning-light) 0%, #fde68a 100%);
    color: #92400e;
    border: 2px solid #fbbf24;
    border-radius: var(--border-radius);
    margin-bottom: 1.5rem;
    font-weight: 500;
    box-shadow: var(--shadow);
}

/* --- Enhanced Accordion --- */
.accordion details {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    margin-bottom: 0.875rem;
    box-shadow: var(--shadow);
    transition: var(--transition);
    overflow: hidden;
}

.accordion details:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-light);
}

.accordion details[open] {
    border-color: var(--primary-color);
}

.accordion summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    color: var(--text-dark);
    transition: var(--transition);
    background: linear-gradient(135deg, transparent 0%, var(--primary-light) 100%);
    background-size: 200% 100%;
    background-position: 100% 0;
}

.accordion summary:hover {
    background-position: 0 0;
}

.accordion summary::-webkit-details-marker {
    display: none;
}

.accordion summary::after {
    content: '›';
    font-size: 1.5rem;
    transform: rotate(90deg);
    transition: var(--transition);
    color: var(--primary-color);
    font-weight: bold;
}

.accordion details[open] > summary::after {
    transform: rotate(-90deg);
}

.summary-count {
    background: linear-gradient(135deg, var(--primary-color) 0%, #4f46e5 100%);
    color: white;
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.25rem 0.625rem;
    border-radius: 99px;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.accordion-content {
    padding: 0 0 1rem 0;
    border-top: 2px solid var(--primary-light);
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.customer-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    transition: var(--transition);
}

.customer-card:hover {
    background-color: var(--primary-light);
}

.customer-card:last-child {
    border-bottom: none;
}

.customer-card-info .customer-name {
    font-weight: 600;
    color: var(--text-dark);
    font-size: 0.9375rem;
}

.customer-card-info span {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* --- Enhanced Modal --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    padding: 1.25rem;
    animation: fadeIn 0.3s ease-out;
}

.modal.hidden {
    display: none;
}

.modal:not(.hidden) {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-card);
    margin: auto;
    padding: 2rem;
    border: none;
    width: 90%;
    max-width: 500px;
    border-radius: var(--border-radius-lg);
    position: relative;
    box-shadow: var(--shadow-xl);
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.close-modal-btn {
    color: var(--text-muted);
    position: absolute;
    top: 1rem;
    right: 1.25rem;
    font-size: 1.75rem;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.close-modal-btn:hover {
    color: var(--danger-color);
    background-color: var(--danger-light);
    transform: rotate(90deg);
}

/* --- Schedule & Tasks --- */
.schedule-actions {
    display: flex;
    gap: 0.875rem;
    flex-wrap: wrap;
    flex-direction: column;
}

.task-card {
    background: linear-gradient(135deg, var(--bg-card) 0%, #f8fafc 100%);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    border: 2px solid transparent;
    transition: var(--transition);
}

.task-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
    transform: translateX(4px);
}

.task-icon {
    font-size: 1.75rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.task-card-info {
    flex-grow: 1;
}

.recurring-days {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.recurring-days label {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    background: var(--primary-light);
    padding: 0.5rem 0.875rem;
    border-radius: 99px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 600;
    transition: var(--transition);
    border: 2px solid transparent;
}

.recurring-days label:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-hover);
}

.suggestion-box {
    border: 2px solid var(--primary-color);
    max-height: 200px;
    overflow-y: auto;
    background: white;
    position: absolute;
    width: calc(100% - 4px);
    z-index: 1002;
    border-radius: 0 0 0.625rem 0.625rem;
    box-shadow: var(--shadow-lg);
}

.suggestion-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid var(--border-color);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background: var(--primary-light);
    color: var(--primary-color);
    font-weight: 600;
}

#scheduleForm .form-group {
    position: relative;
}

.bulk-customer-list {
    max-height: 300px;
    overflow-y: auto;
    border: 2px solid var(--border-color);
    padding: 1.25rem;
    border-radius: 0.875rem;
    margin-bottom: 1.5rem;
    background: var(--primary-light);
}

.schedule-customer-item {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    transition: var(--transition);
}

.schedule-customer-item:hover {
    background: white;
}

.schedule-customer-item label {
    font-weight: 500;
    flex-grow: 1;
    cursor: pointer;
}

/* --- Credit Balance Display --- */
.credit-balance-display {
    padding: 1rem;
    margin-bottom: 1.25rem;
    border-radius: var(--border-radius);
    font-weight: 600;
    text-align: center;
    border: 2px solid;
    font-size: 1.0625rem;
    box-shadow: var(--shadow);
}

.credit-balance-display.due {
    background: linear-gradient(135deg, var(--warning-light) 0%, #fde68a 100%);
    color: #92400e;
    border-color: #fbbf24;
}

.credit-balance-display.advance {
    background: linear-gradient(135deg, var(--secondary-light) 0%, #a7f3d0 100%);
    color: #065f46;
    border-color: var(--secondary-color);
}

/* --- Delivery Portal --- */
#deliveryTasksList,
#pickupTasksList,
#scheduledPickupsList {
    display: flex;
    flex-direction: column;
    gap: 0.875rem;
}

#deliveryCustomerInfo h4 {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--text-dark);
    margin: 0 0 0.75rem 0;
    letter-spacing: -0.025em;
}

#deliveryCustomerInfo p {
    margin: 0.375rem 0;
    color: var(--text-light);
    font-size: 0.9375rem;
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-main);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* --- Responsive Styles --- */
@media (min-width: 901px) {
    .portal-container {
        grid-template-columns: 520px 1fr;
    }

    .portal-container.single-column {
        grid-template-columns: 1fr;
        max-width: 800px;
    }

    .form-actions {
        flex-direction: row;
    }

    .btn {
        width: auto;
    }

    .schedule-actions {
        flex-direction: row;
    }

    .filter-controls {
        flex-direction: row;
    }

    #productTilesContainer {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    }
}
